单片机源程序如下:
#include void delay_1s(void); void seg7s(unsigned char data_seg7); void seg7s2(unsigned char data_seg7); const unsigned char decoder_seg7[10] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void main(void) { WDTCTL=WDTPW+WDTHOLD; P1SEL=0x00; P1SEL2=0x00; P1DIR=0xff; P2SEL=0X00; P2SEL2=0x00; P2DIR=0xff; while(1) { P1OUT=0x81; seg7s(6); seg7s2(9); delay_1s(); P1OUT=0x81; seg7s(5); seg7s2(8); delay_1s(); P1OUT=0x81; seg7s(4); seg7s2(7); delay_1s(); P1OUT=0x81; seg7s(3); seg7s2(6); delay_1s(); P1OUT=0x81; seg7s(2); seg7s2(5); delay_1s(); P1OUT=0x81; seg7s(1); seg7s2(4); delay_1s(); P1OUT=0x82; seg7s(3); seg7s2(3); delay_1s(); P1OUT=0x82; seg7s(2); seg7s2(2); delay_1s(); P1OUT=0x82; seg7s(1); seg7s2(1); delay_1s(); P1OUT=0x24; seg7s(9); seg7s2(6); delay_1s(); P1OUT=0x24; seg7s(8); seg7s2(5); delay_1s(); P1OUT=0x24; seg7s(7); seg7s2(4); delay_1s(); P1OUT=0x24; seg7s(6); seg7s2(3); delay_1s(); P1OUT=0x24; seg7s(5); seg7s2(2); delay_1s(); P1OUT=0x24; seg7s(4); seg7s2(1); delay_1s(); P1OUT=0x44; seg7s(3); seg7s2(3); delay_1s(); P1OUT=0x44; seg7s(2); seg7s2(2); delay_1s(); P1OUT=0x44; seg7s(1); seg7s2(1); delay_1s(); } } void seg7s(unsigned char data_seg7) { unsigned char code_seg7; code_seg7=decoder_seg7[data_seg7]; P2OUT&=~BIT0; if(code_seg7&0x80) //D7 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; if(code_seg7&0x40) //D6 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; if(code_seg7&0x20) //D5 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; if(code_seg7&0x10) //D4 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; if(code_seg7&0x08) //D3 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; if(code_seg7&0x04) //D2 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; if(code_seg7&0x02) //D1 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; if(code_seg7&0x01) //D0 { P2OUT|=BIT1; } else { P2OUT&=~BIT1; } P2OUT|=BIT0; P2OUT&=~BIT0; } void seg7s2(unsigned char data_seg7) { unsigned char code_seg7; code_seg7=decoder_seg7[data_seg7]; P2OUT&=~BIT0; if(code_seg7&0x80) //D7 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; if(code_seg7&0x40) //D6 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; if(code_seg7&0x20) //D5 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; if(code_seg7&0x10) //D4 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; if(code_seg7&0x08) //D3 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; if(code_seg7&0x04) //D2 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; if(code_seg7&0x02) //D1 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; if(code_seg7&0x01) //D0 { P2OUT|=BIT3; } else { P2OUT&=~BIT3; } P2OUT|=BIT2; P2OUT&=~BIT2; } void delay_1s(void) { unsigned long data_delay1s; for(data_delay1s=0;data_delay1s<6654;data_delay1s++); }
上一篇:基于MSP430单片机的温度控制系统设计与实现
下一篇:proteus仿真msp430,实现一个按键矩阵扫描和UART发送
推荐阅读最新更新时间:2024-11-13 11:42
设计资源 培训 开发板 精华推荐
- ADR5044B 4.096 Vout 精密微功率并联模式电压基准的典型应用,用于 ±15 V 输出,具有堆叠 ADR5045 器件
- DC826B-A,用于 LTC2950CTS8-2 开/关控制器的演示板,Vin (26.4V Max) = 2.7V - 26.4V
- 光立方灯控
- EVAL-ADPD1080Z-PRX,用于评估 ADPD1080 长距离接近传感器的评估套件
- 基于stm32f103的传感器控制系统
- 可能是最小的esp8266物联网开发板(8 x gpio)
- 用于可调电流源的 LT1764AEFE LDO 稳压器的典型应用
- DC1067A-A,LTC2450IDC 演示板,16 位高性能,Delta Sigma 模数转换器
- DC1973A,使用 LT8697 USB、5V、2.5A 输出、42V 输入同步降压和电缆压降补偿的演示板
- KITDRIVER2EDN7524RTOBO1,用于 2EDN7524R EiceDRIVER 双通道非隔离栅极驱动器的评估套件