51单片机C语言应用程序实例精讲.rar

时间:2012-09-21 14:24:32
【文件属性】:

文件名称:51单片机C语言应用程序实例精讲.rar

文件大小:648KB

文件格式:RAR

更新时间:2012-09-21 14:24:32

单片机

大量单片机程序和例程可以开发学习#include "7LEDShow.h" void main() { DIGPORT = 0; // 关闭显示 TMOD = 0x01; // T0工作方式1 /* 2ms 定时设置 */ time0_tmp = 65536-time0*fosc/12; TH0 = (time0_tmp/256); TL0 = (time0_tmp%256); TR0 = 1; ET0 = 1; EA = 1; digbit = 0x01; // 从第一位数码管开始 wordbuf[3] = 4; wordbuf[2] = 3; wordbuf[1] = 2; wordbuf[0] = 1; while(1); } /* 定时器0中断服务子程序,定时动态扫描显示 */ void time0_int(void) interrupt 1 { TH0 = (time0_tmp/256); TL0 = (time0_tmp%256); display(); } /* 根据共阴极字型编码表获取0~9,A~B字型代码 */ uchar getcode(uchar i) { uchar p; switch (i) { case 0: p=0x3f; break; /* 0 */ case 1: p=0x06; break; /* 1 */ case 2: p=0x5B; break; /* 2 */ case 3: p=0x4F; break; /* 3 */ case 4: p=0x66; break; /* 4 */ case 5: p=0x6D; break; /* 5 */ case 6: p=0x7D; break; /* 6 */ case 7: p=0x07; break; /* 7 */ case 8: p=0x7F; break; /* 8 */ case 9: p=0x67; break; /* 9 */ case 10: p=0x77; break; /* A */ case 11: p=0x7C; break; /* B */ case 12: p=0x39; break; /* C */ case 13: p=0x5E; break; /* D */ case 14: p=0x79; break; /* E */ case 15: p=0x71; break; /* F */ default: break; } return(p); } /* 显示函数 */ void display(void) { uchar i; switch (digbit) { case 1: i=0;break; case 2: i=1;break; case 4: i=2;break; case 8: i=3;break; default: break; } DIGPORT = 0; // 关闭显示 WORDPORT = getcode(wordbuf[i]); // 送字型码 DIGPORT = digbit; // 送字位码 if (digbit<0x08) digbit = digbit*2; else digbit = 0x01; }


网友评论