程序如下:
/***************************************** 函数名称:void SMG(uchar n,uchar dat) 函数功能:给第n个数码管(共阳)写入数字dat 输入参数:要显示数字的数码管n及数字dat 输出参数:无 *****************************************/ #include "main.h" #define SMG_DSP P2 #define SMG_CS P3
sbit SMG_CS1=P3^0; sbit SMG_CS2=P3^1; sbit SMG_CS3=P3^2; sbit SMG_CS4=P3^3; sbit SMG_CS5=P3^4; sbit SMG_CS6=P3^5; sbit SMG_CS7=P3^6; sbit SMG_CS8=P3^7;
void smg(uchar n,uchar dat) { uchar i; uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99, //0 1 2 3 4 0x92,0x82,0xf8,0x80,0x90, //5 6 7 8 9 0xa0,0x83,0xa7,0xa1,0x84, //a b C d E 0x8e,0xbf}; //F - // 共阳0 - for(i=0;i<20;i++) { SMG_CS=0x00; SMG_DSP=table[dat]; switch(n) { case 1: SMG_CS1=1; delay1ms(1); SMG_CS1=0; break; case 2: SMG_CS2=1; delay1ms(1); SMG_CS2=0; break; case 3: SMG_CS3=1; delay1ms(1); SMG_CS3=0; break; case 4: SMG_CS4=1; delay1ms(1); SMG_CS4=0; break; case 5: SMG_CS5=1; delay1ms(1); SMG_CS5=0; break; case 6: SMG_CS6=1; delay1ms(1); SMG_CS6=0; break; case 7: SMG_CS7=1; delay1ms(1); SMG_CS7=0; break; case 8: SMG_CS8=1; delay1ms(1); SMG_CS8=0; break; } } }
[此贴子已经被作者于2012-7-27 17:05:40编辑过]
|