根据欧浩源老师的数码管动态显示源码改编,基于IAP15K61S2开发。
原本是0xbf的显示为-,但是显示成其他的了,所以改成0x3f才能显示-。
#include#define uchar unsigned char uchar miao=49; uchar fen=59; uchar shi=23; uchar ma[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x3f,0xbf}; void Delay(unsigned int t) { while(t--); } void Delay2(unsigned int J) { while(J--) { smgstaic(); } } void inh(unsigned char n) { switch(n) { case 4: P2=(P2=0x1f)|0x80; break; case 5: P2=(P2=0x1f)|0xa0; break; case 6: P2=(P2=0x1f)|0xc0; break; case 7: P2=(P2=0x1f)|0xe0; break; } } void smg_display(unsigned char dat,unsigned char pos ) { inh(6); P0=0x01< 59) { miao=0; fen++; if(fen>59) {fen=0; shi++; if(shi>23) { shi=0; } } } Delay2(200); } }
以上代码会出现Delay2的C231的报错,常见的改错方式为添加一个宏定义或者将Delay2整体移动到调用Delay2的函数之后。
如果添加宏定义将会出现C231的报错以及C307的报错,仔细检查后原来是宏定义()里的unsigned char J没有写进去,写进去后,又出现了C304报错,最后将宏定义的部分写为以下形式
#define void Delay2( unsigned int J);
解决了报错问题,但是有警告。
如果采用整体后移那么就是以下形式
#include#define uchar unsigned char uchar miao=49; uchar fen=59; uchar shi=23; uchar ma[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x3f,0xbf}; void Delay(unsigned int t) { while(t--); } void inh(unsigned char n) { switch(n) { case 4: P2=(P2=0x1f)|0x80; break; case 5: P2=(P2=0x1f)|0xa0; break; case 6: P2=(P2=0x1f)|0xc0; break; case 7: P2=(P2=0x1f)|0xe0; break; } } void smg_display(unsigned char dat,unsigned char pos ) { inh(6); P0=0x01< 59) { miao=0; fen++; if(fen>59) {fen=0; shi++; if(shi>23) { shi=0; } } } Delay2(200); }
0报错,0警告。每20min有1min误差(毕竟没有时钟,原理还是C语言计数程序)。有需要改正的地方请指出。



