1. 定时器和延时
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include "15W4KxxS4.h" #define FOSC 12000000 #define CLK (65536-FOSC/2/12/1000) sbit clk=P3^0; void clk_wave(void) //1KHZ@12MHz { AUXR |= 0x00; //串口1选择定时器2为波特率发生器 T2L = CLK; //设定定时初值 T2H = CLK>>8; //设定定时初值 AUXR |= 0x10; //启动定时器2 INT_CLKO=0x04; } void Delay5ms() //@12.000MHz { unsigned char i, j; i = 59; j = 90; do { while (--j); } while (--i); } int main(void) { //clk_wave(); while (1) { clk=0; Delay5ms(); clk=1; Delay5ms(); }; }
2. 中断