第37节:数码管作为仪表盘显示跑马灯的方向,速度和状态
时间:11-22
来源:互联网
点击:
- (ucDigShowTemp,0xef);
- break;
- case 6://显示第6位
- ucDigShowTemp=dig_table[ucDigShow6];
- if(ucDigDot6==1)
- {
- ucDigShowTemp=ucDigShowTemp|0x80;//显示小数点
- }
- dig_hc595_drive(ucDigShowTemp,0xdf);
- break;
- case 7://显示第7位
- ucDigShowTemp=dig_table[ucDigShow7];
- if(ucDigDot7==1)
- {
- ucDigShowTemp=ucDigShowTemp|0x80;//显示小数点
- }
- dig_hc595_drive(ucDigShowTemp,0xbf);
- break;
- case 8://显示第8位
- ucDigShowTemp=dig_table[ucDigShow8];
- if(ucDigDot8==1)
- {
- ucDigShowTemp=ucDigShowTemp|0x80;//显示小数点
- }
- dig_hc595_drive(ucDigShowTemp,0x7f);
- break;
- }
- ucDisplayDriveStep++;
- if(ucDisplayDriveStep>8)//扫描完8个数码管后,重新从第一个开始扫描
- {
- ucDisplayDriveStep=1;
- }
- }
- //数码管的74HC595驱动函数
- void dig_hc595_drive(unsigned char ucDigStatusTemp16_09,unsigned char ucDigStatusTemp08_01)
- {
- unsigned char i;
- unsigned char ucTempData;
- dig_hc595_sh_dr=0;
- dig_hc595_st_dr=0;
- ucTempData=ucDigStatusTemp16_09;//先送高8位
- for(i=0;i<8;i++)
- {
- if(ucTempData>=0x80)dig_hc595_ds_dr=1;
- else dig_hc595_ds_dr=0;
- dig_hc595_sh_dr=0; //SH引脚的上升沿把数据送入寄存器
- delay_short(1);
- dig_hc595_sh_dr=1;
- delay_short(1);
- ucTempData=ucTempData<1;
- }
- ucTempData=ucDigStatusTemp08_01;//再先送低8位
- for(i=0;i<8;i++)
- {
- if(ucTempData>=0x80)dig_hc595_ds_dr=1;
- else dig_hc595_ds_dr=0;
- dig_hc595_sh_dr=0; //SH引脚的上升沿把数据送入寄存器
- delay_short(1);
- dig_hc595_sh_dr=1;
- delay_short(1);
- ucTempData=ucTempData<1;
- }
- dig_hc595_st_dr=0;//ST引脚把两个寄存器的数据更新输出到74HC595的输出引脚上并且锁存起来
- delay_short(1);
- dig_hc595_st_dr=1;
- delay_short(1);
- dig_hc595_sh_dr=0; //拉低,抗干扰就增强
- dig_hc595_st_dr=0;
- dig_hc595_ds_dr=0;
- }
- //LED灯的74HC595驱动函数
- void hc595_drive(unsigned char ucLedStatusTemp16_09,unsigned char ucLedStatusTemp08_01)
- {
- unsigned char i;
- unsigned char ucTempData;
- hc595_sh_dr=0;
- hc595_st_dr=0;
- ucTempData=ucLedStatusTemp16_09;//先送高8位
- for(i=0;i<8;i++)
- {
- if(ucTempData>=0x80)hc595_ds_dr=1;
- else hc595_ds_dr=0;
- hc595_sh_dr=0; //SH引脚的上升沿把数据送入寄存器
- delay_short(1);
- hc595_sh_dr=1;
- delay_short(1);
- ucTempData=ucTempData<1;
- }
- ucTempData=ucLedStatusTemp08_01;//再先送低8位
- for(i=0;i<8;i++)
- {
- if(ucTempData>=0x80)hc595_ds_dr=1;
- else hc595_ds_dr=0;
- hc595_sh_dr=0; //SH引脚的上升沿把数据送入寄存器
- delay_short(1);
- hc595_sh_dr=1;
- delay_short(1);
- ucTempData=ucTempData<1;
- }
- hc595_st_dr=0;//ST引脚把两个寄存器的数据更新输出到74HC595的输出引脚上并且锁存起来
- delay_short(1);
- hc595_st_dr=1;
- delay_short(1);
- hc595_sh_dr=0; //拉低,抗干扰就增强
- hc595_st_dr=0;
- hc595_ds_dr=0;
- }
- void led_flicker_09_16() //第9个至第16个LED的跑马灯程序,逐个亮并且每次只能亮一个.
- {
- if(ucLedStartFlag==1)//此变量为1时代表启动
- {
- switch(ucLedStep_09_16)
- {
- case 0:
- if(uiTimeCnt_09_16>=uiSetTimeLevel_09_16) //时间到
- {
- uiTimeCnt_09_16=0; //时间计数器清零
- if(ucLedDirFlag==0)//正方向
- {
- ucLed_dr16=0;//第16个灭
- ucLed_dr9=1;//第9个亮
- ucLed_update=1;//更新显示
- ucLedStep_09_16=1; //切换到下一个步骤
- }
- else//反方向
- {
- ucLed_dr15=1;//第15个亮
- ucLed_dr16=0;//第16个灭
- ucLed_update=1;//更新显示
- ucLedStep_09_16=7; //返回上一个步骤
- }
- }
- break;
- case 1:
- if(uiTimeCnt_09_16>=uiSetTimeLevel_09_16) //时间到
- {
- uiTimeCnt_09_16=0; //时间计数器清零
- if(ucLedDirFlag==0)//正方向
- {
- ucLed_dr9=0;//第9个灭
- ucLed_dr10=1;//第10个亮
- ucLed_update=1;//更新显示
- ucLedStep_09_16=2; //切换到下一个步骤
- }
- else//反方向
- {
- ucLed_dr16=1;//第16个亮
- ucLed_dr
数码管仪表盘跑马 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
