51单片机,动态数码管的程序
单片机源程序如下:
- #include <at89x52.h>
- #include "DongTaiXianShi.h"
- #include "KeyInterrupt.h"
- unsigned char data display_buffer[8];
- unsigned char KeyValue;
- void DisplayData(unsigned int d)
- {
- unsigned char ge,shi,bai,qian,wang;
- display_buffer[7]=16; //显示寄存器器中置显示内容
- display_buffer[6]=16;
- display_buffer[5]=16;
- wang=d/10000;
- qian=(d%10000)/1000;
- bai=(d%1000)/100;
- shi=(d%100)/10;
- ge=d%10;
- if(wang!=0)
- {
- display_buffer[4]=wang;
- display_buffer[3]=qian;
- display_buffer[2]=bai;
- display_buffer[1]=shi;
- display_buffer[0]=ge;
- }
- else
- {
- display_buffer[4]=16;
- if(qian!=0)
- {
- display_buffer[3]=qian;
- display_buffer[2]=bai;
- display_buffer[1]=shi;
- display_buffer[0]=ge;
- }
- else
- {
- display_buffer[3]=16;
- if(bai!=0)
- {
- display_buffer[2]=bai;
- display_buffer[1]=shi;
- display_buffer[0]=ge;
- }
- else
- {
- display_buffer[2]=16;
- if(shi!=0)
- {
- display_buffer[1]=shi;
- display_buffer[0]=ge;
- }
- else
- {
- display_buffer[1]=16;
- display_buffer[0]=ge;
- }
- }
- }
- }
- }
- void main(void)
- {
- unsigned char x=0xED,y=0x5A,OldKeyValue;
- unsigned int z;
- OldKeyValue=KeyValue;
- DongTaiXianShi_init();
- KeyInterrupt_init();
- while(1)
- {
- PCON=0x01; //待机,定时到,在TC0中断服务程序中完成动态数码管显示
- if(KeyValue!=OldKeyValue) //如果有键按下,则执行按键值处理程序
- {
- switch(KeyValue)
- {
- case 0:{z=x+y; break;}
- case 1:{z=x-y; break;}
- case 2:{z=x*y; break;}
- case 3:{z=x/y; break;}
- default: break;
- }
- DisplayData(z);
- OldKeyValue=KeyValue;
- }
- }
- }
复制代码
所有资料51hei提供下载:
动态数码管显示_KeyInterrupt_模块.zip
(71.77 KB, 下载次数: 6)
|