📄 timer.txt
字号:
#include <REG1210.H>
#include <intrins.h>
#include <stdio.h>
#include "ISD51.h"
#include "ROM.H"
#define XTAL 11059200 // XTAL frequency 11.0592 MHz
// defines for UART BAUDRATE
#define BAUDRATE 9600 // 9600bps communication baudrate
#define T2RELOAD (65536-(XTAL/32/BAUDRATE))
sbit RedLed = P2^0; //EVM Led
sbit YellowLed = P2^1; //EVM Led
extern unsigned char i=0x100; //每32次T0中断使EVM板上的指示灯闪烁
//定时器中断
void Interrupt (void) interrupt 1 {
TL0=0x00; //定时器重新赋值
TH0=0x00;
i=i-1;
if(!i){
RedLed=!RedLed;
YellowLed=!YellowLed;
i=0x100;
printf("Dingshiqi\n");
}
else
;
}
void main (void) {
//Config ISD
T2CON = 0x34; // Use Timer 2 as baudrate generator
RCAP2H = 0xFF;
RCAP2H = (T2RELOAD >> 8); // baudrate reload factor
RCAP2L = T2RELOAD;
SCON0 = 0x50; // enable serial uart & receiver
PCON |= 0x80; // double baudrate for UART0
P3DDRL &= 0xF0; // P3DDRL set port pins of UART0 to input/strong drive output
P3DDRL |= 0x07; // P3DDRL set port pins of UART0 to input/strong drive output
USEC = ((XTAL+500000)/1000000)-1; // USEC timer factor
ONEMS = (XTAL/1000)-1; // (MSECH+MSCL) MS Timer counting at 1.0ms
HMSEC = 100-1; // Hundred MS Timer to 100.0ms
SECINT = (10-1) | 0x80; // SECINT= 10 * HMS Timer Rate = 1 sec
// '0x80' will set the MSB for write immediate
MSINT = (10-1) | 0x80; // MSINT = 10ms for Tone period time base
PDCON = 0x1D; // Powerup SysTimer
FTCON = 0xA5; // setup flash programming times
EICON = 0x40; //DIS enable all auxiliary interrupts
EA = 1; //DIS Enable global interrupt flag
ISDwait (); // wait for connection to uVision2 Debugger
//Insert your own program here
SP=0x60;
CKCON=0x18; //设置定时器计时基准时钟
TMOD=0x01; //定时器0工作与方式1
TL0=0x00;
TH0=0x00;
TR0=1;
ET0=1;
while(1); //等待中断
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -