这是我做的电子设计,用了两个星期。和C语言代码。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<regx51.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define LED P0
- sbit CS2 = P2^2;
- sbit CS1 = P2^1;
- uchar count;
- uchar counth,countl;
- const uchar tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
- unsigned int temp;
- unsigned int fin;
- void delayms()//延时函数
- {
- uint i;
- for(i=0; i<130; i++);
- }
- void it0(void) interrupt 0 using 1
- {
-
- if(temp==1&&count!=0&&fin==0){
- count--;
- temp=0;
- }else{
- temp=1;
- }
- fin=1;
- }
- void it2(void) interrupt 2 using 2
- {
- if(temp==1&&count<99&&fin==1){
- fin=0;
- count++;
- temp=0;
- }else{
- temp=1;
- }
- fin=0;
- }
- void main(void)
- {
- IT0=1;
- IT1=1;
- EA=1;
- EX0=1;
- EX1=1;
- PX1=1;
- fin=1;
- while(1){
- counth=count/10;
- countl=count%10;
- LED= tab[countl];
- CS2=1;
- delayms();
- CS2=0;
- LED=tab[counth];
- CS1=1;
- delayms();
- CS1=0;
- }
- }
复制代码 由于我是新手以上资料肯定存在一些错误,欢迎大家批评指正,一起学习 提高技术(仅供参考 切勿照搬)
|