【单片机学习】共阳数码管的动态显示
生活随笔
收集整理的這篇文章主要介紹了
【单片机学习】共阳数码管的动态显示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:
在8位數碼管中,前面4位顯示年份“2018”,接著2位是分割符“—”,最后兩位是月份,從1月份開始,每隔一段時間加1個月,到12月之后又從1月份開始遞增,如此往復。
#include "reg52.h"unsigned char month=1; //定義月份//共陽極數碼管 unsigned char code duan_code[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,0xbf,0x7f};//選擇鎖存器 void Select_HC573(unsigned char n) {switch(n){case 4:P2=(P2&0x1f)|0x80;break;case 5:P2=(P2&0x1f)|0xa0;break;case 6:P2=(P2&0x1f)|0xc0;break;case 7:P2=(P2&0x1f)|0xe0;break;} }void SEG_Bit(unsigned char pos,unsigned char value) {Select_HC573(6); //位選P0=0x01<<pos;Select_HC573(7); //段選P0=value; }//數碼管延時函數 void Delay_SEG(unsigned int t) {while(t--); }//數碼管靜態顯示 void SEG_Dynamic() {SEG_Bit(0,duan_code[2]); //2Delay_SEG(500);SEG_Bit(1,duan_code[0]); //0Delay_SEG(500);SEG_Bit(2,duan_code[1]); //1Delay_SEG(500);SEG_Bit(3,duan_code[8]); //8Delay_SEG(500);SEG_Bit(4,duan_code[16]); //-Delay_SEG(500);SEG_Bit(5,duan_code[16]); //-Delay_SEG(500);SEG_Bit(6,duan_code[month/10]); //月份的十位Delay_SEG(500);SEG_Bit(7,duan_code[month%10]); //月份的個位Delay_SEG(500); }void delay(unsigned char t) {while(t--){SEG_Dynamic();}}void main() {while(1){SEG_Dynamic();month++;if(month>12){month=1;}delay(100);} }總結
以上是生活随笔為你收集整理的【单片机学习】共阳数码管的动态显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 啊哈,算法自学记——6th
- 下一篇: win7开启uasp协议_WIN7 US