|
求大神指点一下 用74hc595和中断驱动 一位数码管; 帮忙给看下 万分感谢
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit CP = P2^0;
sbit DA = P2^1;
sbit LE = P2^2;
uchar sec,a,b;
uchar code seg[] = {
0xc0, 0xf9, 0xa4, 0xb0, 0x99,
0x92, 0x82, 0xf8, 0x80, 0x10};
uchar dis_buff[1] = {0};
void write_595(uchar dat)//д??595
{
uchar i;
for(i = 0; i < 8; i++) {
DA = dat & 0x80;
CP = 0;
CP = 1;
dat <<= 1;
}
}
void update(uchar sec) //
{
dis_buff[0] =seg[sec]; // sec ????1????????????????
}
void display()
{
write_595(dis_buff[0]); //dis_buff[0] ?е???? ????write_595;
LE = 0;
LE = 1; //?????????????
}
void timer0_isr() interrupt 1 //?ж??????????
{
TMOD = 0X01;
TH0 = 0x4c;
EA = 1;
ET0 = 1;
TR0 = 1;
a++;
if(a%5==0)
{
b = ~b;
update(); //??sec ????dis_buff[0]?У? ???磺sec = 1? ??浽dis_buff[0]???У?
} //???
if(a == 20)
{
display(); //dis_buff[0] ?е???? ????write_595;
a = 0;
sec++;
}
if(sec==9) sec = 0;
}
void timer0_init(void)
{
TMOD = 0x01;//T0??????1
TH0 = 0x4c; //50ms@11.0592MHz
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main()
{
tiemr0_init();
while(1);
}
|
|