本帖最后由 378498084 于 2018-4-18 21:16 编辑
#include "upsd_hardware.h" // 开发板硬件定义
#include "upsd3200.h" // UPSD单片机特殊寄存器声明头文件
#include <stdio.h>
sbit L1=P4^5;
static unsigned int idata timer0_tick;
unsigned int timer0_count(void);
#define TIMER0_VALUE-(((FREQ_OSC * 10L) / 12L) - 17L)#define Watchdog_Off() WDKEY=0x55
void UartInit(); //串口初始化程序
void UartInit()
{
T2MOD = 0; //timer2
T2CON = 0x30;
RCAP2L = 0x8B; //计数器重装值
RCAP2H = 0xFF;
TL2 = 0x8B; //baud rate = 9600
TH2 = 0xFF;
SCON |= 0x52; //mode 1, REN = 1,TI=1
PCON = 0x00;
TI = 1;
TR2 = 1; //enable timer2
}
void timer0_init(void) // chushihua
{
EA = 0;
timer0_tick = 0;
TR0 = 0;
TMOD &= 0xF0;
TMOD |= 0x01;
TL0 = (TIMER0_VALUE & 0x00FF);
TH0 = (TIMER0_VALUE >> 8);
PT0 = 1;
ET0 = 1;
TR0 = 1;
EA = 1;
}
static void timer0_isr(void) interrupt TF0_VECTOR using 1
{
TR0 = OFF;
TL0= (TIMER0_VALUE & 0x00FF);
TH0 = (TIMER0_VALUE >> 8);
TR0 = ON;
timer0_tick++;
}
unsigned int timer0_count(void) //
{
unsigned int t;
EA = 0;
t = timer0_tick;
EA = 1;
return(t);
}
void main(void){
Watchdog_Off();
UartInit();
timer0_init();
while(1)
{
if(timer0_tick==2)
{
L1=!L1;
timer0_tick=0;
}
}
}
|