第10节:一个用来学习C语言的模板程序
Data5,GuiWdData6,GuiWdData7,GuiWdData8,GuiWdData9。这10个窗口变量是给大家调试专用的,8位数码管可以切换显示10个窗口变量,最左边2位数码管代表窗口变量号,剩下6位数码管显示十进制的窗口变量数值,另外16个LED实时显示此数据的二进制格式。最左边2位数码管从“0-”到“9-”代表从第0个窗口变量到第9个窗口变量,也就是GuiWdData0依次到GuiWdData9。用S1和S5按键可以切换显示不同的窗口变量,按住S9不放可以观察到当前窗口变量的十六进制格式数据,松开S9按键后,又自动返回显示当前窗口变量的十进制数据。
该模板程序是基于坚鸿51学习板,现在跟大家分享这个程序,要让这10个窗口变量分别显示10,11,12,13,14,15,16,17,18,19这10个数,用S1按键可以切换显示从小往大的窗口变量号,用S5按键可以切换显示从大往小的窗口变量号。再强调一次,大家只需要关注主程序main函数的初始化区域就可以了,其它的代码请直接复制过来,不用理解。比如:
void main() //主程序
{
//...初始化区域
while(1)
{
}
}
详细的源代码如下:
#include "REG52.H"
#define const_voice_short 40
#define const_key_time1 20
#define const_key_time2 20
#define const_key_time3 20
void initial(void);
void delay_short(unsigned int uiDelayShort);
void dig_hc595_drive(unsigned char ucDigStatusTemp16_09,unsigned char ucDigStatusTemp08_01);
void display_drive(void);
void display_service(void);
void hc595_drive(unsigned char ucLedStatusTemp16_09,unsigned char ucLedStatusTemp08_01);
void T0_time(void);
void key_service(void);
void key_scan(void);
sbit beep_dr=P2^7;
sbit key_sr1=P0^0;
sbit key_sr2=P0^1;
sbit key_sr3=P0^2;
sbit key_gnd_dr=P0^4;
sbit led_dr=P3^5;
sbit dig_hc595_sh_dr=P2^0;
sbit dig_hc595_st_dr=P2^1;
sbit dig_hc595_ds_dr=P2^2;
sbit hc595_sh_dr=P2^3;
sbit hc595_st_dr=P2^4;
sbit hc595_ds_dr=P2^5;
unsigned char GucKeySec=0;
unsigned char GucKey3Sr=1;
unsigned int GuiVoiceCnt=0;
unsigned char GucVoiceStart=0;
unsigned char GucDigShow8;
unsigned char GucDigShow7;
unsigned char GucDigShow6;
unsigned char GucDigShow5;
unsigned char GucDigShow4;
unsigned char GucDigShow3;
unsigned char GucDigShow2;
unsigned char GucDigShow1;
unsigned char GucDisplayUpdate=1;
unsigned char GucWd=0;
unsigned int GuiWdData0=0;
unsigned int GuiWdData1=0;
unsigned int GuiWdData2=0;
unsigned int GuiWdData3=0;
unsigned int GuiWdData4=0;
unsigned int GuiWdData5=0;
unsigned int GuiWdData6=0;
unsigned int GuiWdData7=0;
unsigned int GuiWdData8=0;
unsigned int GuiWdData9=0;
code unsigned char dig_table[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40,
};
void main() //主程序
{
/*---C语言学习区域的开始---------------------------------------------------------------------------*/
GuiWdData0=10; //把10这个数值放到窗口变量0里面显示
GuiWdData1=11; //把11这个数值放到窗口变量1里面显示
GuiWdData2=12; //把12这个数值放到窗口变量2里面显示
GuiWdData3=13; //把13这个数值放到窗口变量3里面显示
GuiWdData4=14; //把14这个数值放到窗口变量4里面显示
GuiWdData5=15; //把15这个数值放到窗口变量5里面显示
GuiWdData6=16; //把16这个数值放到窗口变量6里面显示
GuiWdData7=17; //把17这个数值放到窗口变量7里面显示
GuiWdData8=18; //把18这个数值放到窗口变量8里面显示
GuiWdData9=19; //把19这个数值放到窗口变量9里面显示
/*---C语言学习区域的结束---------------------------------------------------------------------------*/
while(1)
{
initial();
key_service();
display_service();
}
}
void display_service(void)
{
static unsigned char SucLedStatus16_09=0;
static unsigned char SucLedStatus08_01=0;
static unsigned int SinWdDataTemp=0;
if(1==GucDisplayUpdate)
{
GucDisplayUpdate=0;
switch(GucWd)
{
case 0:
GucDigShow8=0;
SinWdDataTemp=GuiWdData0;
break;
case 1:
GucDigShow8=1;
SinWdDataTemp=GuiWdData1;
break;
case 2:
GucDigShow8=2;
SinWdDataTemp=GuiWdData2;
break;
case 3:
GucDigShow8=3;
SinWdDataTemp=GuiWdData3;
break;
case 4:
GucDigShow8=4;
SinWdDataTemp=GuiWdData4;
break;
C语言模板程序单片 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)