線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1076
推到 Plurk!
推到 Facebook!

C8051F 計時器問題

尚未結案
a750707123
一般會員


發表:1
回覆:0
積分:0
註冊:2013-05-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2013-05-07 07:13:50 IP:140.116.xxx.xxx 訂閱
 我想撰寫一段類似碼錶功能的C8051F330 CODE
但目前尚未知道他的port腳如何定義
EX:我希望他的P0.0可以當作開始、停止用

以下是我目前所寫
reset後可以計時,但是我想宣告一隻腳為做為開始與暫停用,還不知道怎麼寫
#include "C8051f330.h"
#include "HC164.h"
/*
================================================================================
----------------------------Internal static variables---------------------------
================================================================================
*/
static volatile unsigned char Counter_ms = 0;
static code Charecter[10] = { 0xC0, 0xf9, 0xA4, 0xB0, 0x99, 0x92, 0X82, 0xF8, 0x80, 0x90};
unsigned char DisplayValue[4] = {0, 0, 0, 0};
void HC138_Sel( unsigned char x )
{
P1MDOUT |= ( 1<<2 ) | ( 1<<3 ) | ( 1<<4 );
P1 &= ( ( x<<2 ) | 0xE3 );
}
/*
================================================================================
* Name : Timer3Init( )
* Description : Initialize timer3, 1ms overflow
* Input : None
* Output : None
* Note : None
================================================================================
*/
static void Timer3Init( void )
{
TMR3RLH = 0xf9;
TMR3RLL = 0x66;
TMR3H = 0xf9;
TMR3L = 0x66;
TMR3CN = 0x04;
EIE1 |= ( 1<<7 );
}
/*
================================================================================
* Name : Timer3_ISR( )
* Description : Interrupt service routine for timer3
* Input : None
* Output : None
* Note : None
================================================================================
*/
static unsigned char Disbit = 0x0;
static Timer3_ISR( void ) interrupt 14
{
TMR3CN &= ~( 1<<7 );
Counter_ms ;
if( Disbit > 4 )
{
Disbit = 1;
}
HC164_Clear( );
HC138_Sel( Disbit );
}
/*
================================================================================
* Name : Delay10Ms( )
* Description : Delay for some times
* Input : None
* Output : None
* Note : None
================================================================================
*/
static void DelayMs( unsigned char dly )
{
while( dly-- )
{
Counter_ms = 0;
while( Counter_ms == 0 );
}
}
/*
================================================================================
* Name : ClockInit( )
* Description : Initialize the system clock
* Input : None
* Output : None
* Note : None
================================================================================
*/
static void ClockInit( void )
{
unsigned char tmp;
GPIOInit( );
P1 &= ~0x1C;
HC164_Output( 7 );
DelayMs( 50 );
//if(P0_0==0){
DisplayValue[0] = 0;
DisplayValue[1] = 0;
DisplayValue[2] = 0;
DisplayValue[3] = 0;
}
}
}
return 0;
}
系統時間:2024-04-25 16:47:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!