这篇写的不是很好,建议别看了,
一.单片机的外部中断
按键,普通的io接口靠主循环,发现你按键按下,才会做一个操作
数码管的显示方式与(四),K1按下,INT0受到低电平的触发
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit k3=P3^3
sbit k4=P3^5
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
};
uchar code Scan_BTTs[]=
{
0X20,0X10,0X08,0X04,0X02,0X01
};
uchar data Butter_Counts[]={0,0,0,0,0,0,0}
uint Count_A=0;
uint Count_B=0;
二.定时器
void main()
{
P0=0x3f;
P2=0x3f;
i=0;
Second_Counts=0;
Key_State=1;
TMOD=0x01;//定时器设置
TH0=(65535-50000)/256;//定时器初值
TL0=(65535-50000)%256; //设置时间50ms
while(1)
{
if(Key_State!=K1)
{
DelayMS(10);
Key_State=K1;
Key_Event_Handle();
}
}
}
void DSY_Refresh() interrupt
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
if(++i==2) //100MS
{
i=0;
++Second_Counts;
P0=DSY_CODE[Second_Counts/10];
P2=DSY_CODE[Second_Counts%10];
if(Second_Counts==100)Second_Counts==0;
}
}
串口 用USB转TTL
这篇写的不是很好,建议别看了,