资源描述:
《七段共阴极数码管驱动.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、硬件原理七段共阴极数码管驱动逻辑:在点亮其中任意一段时,其它的段要off,然后用定时器按顺序点亮需要的段以组合起来想要显示的内容。控制IO的IO方向是可选的(led是电流控制器件,通过设置IO的方向可以控制端口的电流),用设为输出的方式来点亮led,设为输入的方式来关灭led。#ifndef_led_c_#define_led_c_#defineDIR_1PCDIR.1#defineDIR_2PCDIR.2#defineDIR_3PCDIR.5#defineDIR_4PCDIR.7#defineDIR_
2、5PCDIR.9#defineDIR_6PBDIR.6#defineDIR_7PBDIR.9#defineOD_1PCOD.1#defineOD_2PCOD.2#defineOD_3PCOD.5#defineOD_4PCOD.7#defineOD_5PCOD.9#defineOD_6PBOD.6#defineOD_7PBOD.9__Xunsignedcharled_process_state;__Xunsignedcharled_num_one;__Xunsignedcharled_num_two;__
3、Xunsignedcharled_num_three;__Xunsignedcharled_num_four;__Xunsignedcharled_count;__Xunsignedlongled_timer;//voidled_key_display(unsignedcharnum_val,unsignedchartimer);voidled_1_display(unsignedcharnum_val);voidled_2_display(unsignedcharnum_val);voidled_3_
4、display(unsignedcharnum_val);voidled_4_display(unsignedcharnum_val);void__interruptled_process(void);/***********************************************************//对应的数字显示控制***********************************************************/__Xunsignedcharled_tab
5、[10][8]={{'a','b','c','d','e','f',' '},//0{'b','c',' '},//1{'a','b','d','e','g',' '},//2{'a','b','c','d','g',' '},//3{'b','c','f','g',' '},//4{'a','c','d','f','g',' '},//5{'a','c','d','e','f','g',' '},//6{'a','b','c',' '},//7{'a','b','c','d','e',
6、'f','g',' '},//8{'a','b','c','d','f','g',' '}//9};/***********************************************************//Timerinterruption***********************************************************/void__interruptled_process(void){__asm{BSETDIR_1BSETDIR_2BSETDI
7、R_3BSETDIR_4BSETDIR_5BSETDIR_6BSETDIR_7}switch(led_process_state){case0://LED_D_MID__asm{BCLRDIR_3BCLROD_3BCLRDIR_4BSETOD_4}led_process_state++;break;case1://LED_D_MP3 __asm{BCLRDIR_7BCLROD_7BCLRDIR_3BSETOD_3}led_process_state++;break;case2://LED_D_PN_
8、_asm{BCLRDIR_3BCLROD_3BCLRDIR_6BSETOD_6}led_process_state++;break;case3://LED_D_RF__asm{BCLRDIR_3BCLROD_3BCLRDIR_7BSETOD_7}led_process_state++;break;case4://LED_D_SD__asm{BCLRDIR_1BCLROD_1BCLRDIR_5BSETOD_5}led_process_stat