久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3008|回復: 1
打印 上一主題 下一主題
收起左側

單片機16燈流水燈程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:351485 發(fā)表于 2018-6-13 23:01 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  • #include <REG52.H>
  • unsigned char RunMode;
  • //**********************************System Fuction*************************************************
  • void Delay1ms(unsigned int count)
  • {
  •         unsigned int i,j;
  •         for(i=0;i<count;i++)
  •         for(j=0;j<120;j++);
  • }
  • unsigned char code LEDDisplayCode[] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,        //0~7
  •                                                           0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};
  • void Display(unsigned char Value)
  • {
  •         P3 = LEDDisplayCode[Value];
  • }
  • void LEDFlash(unsigned char Count)
  • {
  •         unsigned char i;
  •         bit Flag;
  •         for(i = 0; i<Count;i++)
  •         {
  •                 Flag = !Flag;
  •                 if(Flag)
  •                         Display(RunMode);
  •                 else
  •                         Display(0x10);
  •                 Delay1ms(100);
  •         }
  •         Display(RunMode);
  • }
  • unsigned char GetKey(void)
  • {
  •         unsigned char KeyTemp,CheckValue,Key = 0x00;
  •         CheckValue = P2&0x32;
  •         if(CheckValue==0x32)
  •                 return 0x00;
  •         Delay1ms(10);
  •         KeyTemp = P2&0x32;
  •         if(KeyTemp==CheckValue)
  •                 return 0x00;
  •         if(!(CheckValue&0x02))
  •                 Key|=0x01;
  •         if(!(CheckValue&0x10))
  •                 Key|=0x02;
  •         if(!(CheckValue&0x20))
  •                 Key|=0x04;
  •         return Key;
  • }
  • unsigned int TimerCount,SystemSpeed,SystemSpeedIndex;
  • void InitialTimer2(void)
  • {
  •         T2CON  = 0x00;                        //16 Bit Auto-Reload Mode
  •          TH2 = RCAP2H = 0xFC;          //重裝值,初始值        TL2 = RCAP2L = 0x18;
  •         ET2=1;                                        //定時器 2 中斷允許
  •         TR2 = 1;                                //定時器 2 啟動
  •         EA=1;
  • }
  • unsigned int code SpeedCode[]={   1,   2,   3,   5,   8,  10,  14,  17,  20,  30,
  •                                                              40,  50,  60,  70,  80,  90, 100, 120, 140, 160,
  •                                                                 180, 200, 300, 400, 500, 600, 700, 800, 900,1000};//30
  • void SetSpeed(unsigned char Speed)
  • {
  •         SystemSpeed =SpeedCode[Speed];
  • }
  • void LEDShow(unsigned int LEDStatus)
  • {
  •         P1 = ~(LEDStatus&0x00FF);
  •         P0 = ~((LEDStatus>>8)&0x00FF);
  • }
  • void InitialCPU(void)
  • {
  •         RunMode = 0x00;
  •         TimerCount = 0;
  •         SystemSpeedIndex = 10;
  •         P1 = 0x00;
  •         P0 = 0x00;
  •         P2 = 0xFF;
  •         P3 = 0x00;
  •         Delay1ms(500);
  •         P1 = 0xFF;
  •         P0 = 0xFF;
  •         P2 = 0xFF;
  •         P3 = 0xFF;
  •         SetSpeed(SystemSpeedIndex);
  •         Display(RunMode);
  • }
  • //Mode 0
  • unsigned int LEDIndex = 0;
  • bit LEDDirection = 1,LEDFlag = 1;
  • void Mode_0(void)
  • {
  •         LEDShow(0x0001<<LEDIndex);
  •         LEDIndex = (LEDIndex+1)%16;
  • }
  • //Mode 1
  • void Mode_1(void)
  • {
  •         LEDShow(0x8000>>LEDIndex);
  •         LEDIndex = (LEDIndex+1)%16;
  • }
  • //Mode 2
  • void Mode_2(void)
  • {
  •         if(LEDDirection)
  •                 LEDShow(0x0001<<LEDIndex);
  •         else
  •                 LEDShow(0x8000>>LEDIndex);
  •         if(LEDIndex==15)
  •                 LEDDirection = !LEDDirection;
  •    LEDIndex = (LEDIndex+1)%16;
  • }
  • //Mode 3
  • void Mode_3(void)
  • {
  •         if(LEDDirection)
  •                 LEDShow(~(0x0001<<LEDIndex));
  •         else
  •                 LEDShow(~(0x8000>>LEDIndex));
  •         if(LEDIndex==15)
  •                 LEDDirection = !LEDDirection;
  •    LEDIndex = (LEDIndex+1)%16;
  • }
  • //Mode 4
  • void Mode_4(void)
  • {
  •         if(LEDDirection)
  •         {
  •                 if(LEDFlag)
  •                         LEDShow(0xFFFE<<LEDIndex);
  •                    else
  •                         LEDShow(~(0x7FFF>>LEDIndex));
  •         }
  •         else
  •         {
  •                 if(LEDFlag)
  •                         LEDShow(0x7FFF>>LEDIndex);
  •                 else
  •                         LEDShow(~(0xFFFE<<LEDIndex));
  •         }
  •         if(LEDIndex==15)
  •         {
  •                 LEDDirection = !LEDDirection;
  •                 if(LEDDirection)        LEDFlag = !LEDFlag;
  •         }
  •            LEDIndex = (LEDIndex+1)%16;
  • }
  • //Mode 5
  • void Mode_5(void)
  • {
  •         if(LEDDirection)
  •                 LEDShow(0x000F<<LEDIndex);
  •         else
  •                 LEDShow(0xF000>>LEDIndex);
  •         if(LEDIndex==15)
  •                 LEDDirection = !LEDDirection;
  •     LEDIndex = (LEDIndex+1)%16;
  • }
  • //Mode 6
  • void Mode_6(void)
  • {
  •         if(LEDDirection)
  •                 LEDShow(~(0x000F<<LEDIndex));
  •         else
  •                 LEDShow(~(0xF000>>LEDIndex));
  •         if(LEDIndex==15)
  •                 LEDDirection = !LEDDirection;
  •            LEDIndex = (LEDIndex+1)%16;
  • }
  • //Mode 7
  • void Mode_7(void)
  • {
  •         if(LEDDirection)
  •                 LEDShow(0x003F<<LEDIndex);
  •         else
  •                 LEDShow(0xFC00>>LEDIndex);
  •         if(LEDIndex==9)
  •                 LEDDirection = !LEDDirection;
  •     LEDIndex = (LEDIndex+1)%10;
  • }
  • //Mode 8
  • void Mode_8(void)
  • {
  •         LEDShow(++LEDIndex);
  • }
  • void TimerEventRun(void)
  • {
  •         if(RunMode==0x00)
  •         {
  •                 Mode_0();
  •         }
  •         else if(RunMode ==0x01)
  •         {
  •                 Mode_1();
  •         }
  •         else if(RunMode ==0x02)
  •         {
  •                 Mode_2();
  •         }
  •         else if(RunMode ==0x03)
  •         {
  •                 Mode_3();
  •         }
  •         else if(RunMode ==0x04)
  •         {
  •                 Mode_4();
  •         }
  •         else if(RunMode ==0x05)
  •         {
  •                 Mode_5();
  •         }
  •         else if(RunMode ==0x06)
  •         {
  •                 Mode_6();
  •         }
  •         else if(RunMode ==0x07)
  •         {
  •                 Mode_7();
  •         }
  •         else if(RunMode ==0x08)
  •         {
  •                 Mode_8();
  •         }
  • }
  • void Timer2(void) interrupt 5 using 3
  • {
  •         TF2 = 0;         //中斷標志清除( Timer2 必須軟件清標志!)
  •         if(++TimerCount>=SystemSpeed)
  •         {
  •                 TimerCount = 0;
  •                 TimerEventRun();
  •            }
  • }
  • unsigned char MusicIndex = 0;
  • void KeyDispose(unsigned char Key)
  • {
  •         if(Key&0x01)
  •         {
  •                 LEDDirection = 1;
  •                 LEDIndex = 0;
  •                 LEDFlag = 1;
  •                 RunMode = (RunMode+1)%9;
  •                 Display(RunMode);
  •         }
  •         if(Key&0x02)
  •         {
  •                 if(SystemSpeedIndex>0)
  •                 {
  •                         --SystemSpeedIndex;
  •                         SetSpeed(SystemSpeedIndex);
  •                 }
  •                 else
  •                 {
  •                         LEDFlash(6);
  •                 }
  •         }
  •         if(Key&0x04)
  •         {
  •                 if(SystemSpeedIndex<28)
  •                 {
  •                         ++SystemSpeedIndex;
  •                         SetSpeed(SystemSpeedIndex);
  •                 }
  •                 else
  •                 {
  •                         LEDFlash(6);
  •                 }
  •         }
  • }
  • //***********************************************************************************
  • main()
  • {
  •         unsigned char Key;
  •         InitialCPU();
  •         InitialTimer2();
  •         while(1)
  •         {
  •                 Key = GetKey();
  •                 if(Key!=0x00)
  •                 {
  •                         KeyDispose(Key);
  •                 }
  •         }
  • }
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:334550 發(fā)表于 2018-7-9 17:17 | 只看該作者
請問樓主 我用的單片機是15F204S   IO口有  p3.0 到P3.3   P3.6 P3.7  P1.0 到 P1.5  P5.4  P5.5   如何寫呢  ,按指令移動的話  我這個單片機的IO口 都不聯(lián)著,如何移動啊?  現在只會把每個IO口定義一下,然后再寫,
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产美女精品 | 久久9热 | 亚洲在线一区二区 | 日韩一级免费大片 | av中文字幕在线观看 | 激情五月综合 | 亚洲欧美日韩中文在线 | 久久99深爱久久99精品 | 一区二区三区在线免费观看 | 久久久做 | 精品粉嫩aⅴ一区二区三区四区 | 精品一区二区三区中文字幕 | 午夜精品影院 | 久热国产在线 | 欧美亚洲视频 | 午夜精品久久久久久久99黑人 | 亚洲精品一二三区 | 中文字幕在线免费观看 | 麻豆视频国产在线观看 | 中文字幕第一页在线 | 亚洲精品无人区 | 丁香综合| 午夜精品久久 | 欧美激情一区二区三区 | 欧美一级在线 | 中文字幕一页二页 | 日本黄色大片免费看 | 日韩综合在线视频 | 国产精品久久久久久久久久久久久 | 自拍偷拍亚洲一区 | 99亚洲精品 | 国产精品一区二区日韩 | 久久精品91久久久久久再现 | 亚洲精品久久 | 亚洲成人精品一区二区 | 91久久精品日日躁夜夜躁国产 | 国产1区| 有码在线 | 国产高清精品一区二区三区 | 国产网站在线免费观看 | 激情毛片 |