日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

单片机c语言必背100代码,单片机C语言代码手册 含100多个经典C程序.pdf

發布時間:2023/12/10 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 单片机c语言必背100代码,单片机C语言代码手册 含100多个经典C程序.pdf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

單片機C語言代碼手冊 含100多個經典C程序.pdf

1 單片機單片機 C 語言代碼手冊語言代碼手冊 1 LED 燈燈 點亮一個點亮一個 LED include void main while 1 P0 0 x01 P2 0 x7d 流水燈閃爍流水燈閃爍 include sbit LED P0 0 void delay unsigned int i unsigned int j for i i 0 i for j 110 j 0 j void main LED 0 delay 60 LED 1 delay 10 流水燈流水燈 左移左移 include include unsigned char aa void delay unsigned int xms unsigned int i j for i xms i 0 i for j 110 j 0 j void main aa 0 xfe while 1 P0 aa delay 1000 aa crol aa 1 跑馬燈跑馬燈 include include void delayms unsigned char ms unsigned char i while ms for i 0 i 120 i void main unsigned char LED LED 0 xfe 11111110 P2 LED while 1 delayms 250 LED crol LED 1 循環右移 1位 點亮下一個LED P2 LED 用循環移位指令實現用循環移位指令實現 LED 流水燈效果流水燈效果 include include void delayms unsigned char i 延時子程序 unsigned char j while i for j 0 j 120 j void main unsigned char LED LED 0 xfe 0 xfe 1111 1110 while 1 P2 LED delayms 250 LED LED 1 循環右移 1 位 點亮下一個 LED 為左移 位 if LED 0 x00 LED 0 xfe 0 xfe 1111 1110 左右跑馬燈左右跑馬燈 include void delay unsigned int i unsigned char j for i i 0 i for j 255 j 0 j char LED void main unsigned char i while 1 LED 0 xfe for i 0 i 8 i P2 LED delay 500 LED LED 1 左移 LED LED 0 x01 移位后 后面的位為高電平 2 if LED 0 x7f break 提前退出 FOR 循環 for i 0 i 1 右移 LED LED 0 x80 移位后 后面的位為高電平 LED 作二進制加法作二進制加法 include void delay unsigned int i unsigned char j for i i 0 i for j 255 j 0 j void main unsigned char Num 0 xff while 1 P2 Num delay 1000 Num LED 閃爍閃爍 定時器定時器 include include unsigned char num aa 0 xfe void main TMOD 0 x01 TH0 65536 45872 256 TL0 65536 45872 256 EA 1 ET0 1 TR0 1 while 1 if num 1 num 0 P2 aa aa crol aa 1 void T0 time interrupt 1 TH0 65536 45872 256 TL0 65536 45872 256 num 2 數碼管數碼管 0 9 顯示顯示 include void delay2ms unsigned int delaytime unsigned int cnt for cnt 0 cnt9 cnt 0 delay2ms 2500 95 顯示顯示 include void delay2ms unsigned int delaytime unsigned int cnt for cnt 0 cnt delaytime 50 cnt unsigned char s 10 0 x3f 0 x06 0 x5b 0 x4f 0 x66 0 x6d 0 x7d 0 x07 0 x7f 0 x6f main unsigned char num 95 unsigned char cnt 0 while 1 switch cnt 2 case 0 P0 0 x02 P2 s num 10 break case 1 P0 0 x04 P2 s num 10 break delay2ms 1 138 片選實現動態顯示片選實現動態顯示 include include sbit LS138A P2 2 定義LS138譯碼器的輸入A腳由P2 2控制 sbit LS138B P2 3 定義LS138譯碼器的輸入 B腳由P2 3控制 sbit LS138C P2 4 定義LS138譯碼器的輸入 C腳由P2 4控制 void delay unsigned int i 函數聲名 char cnt unsigned char code Disp Tab 共陰數碼管 0 9 0 x3f 0 x06 0 x5b 0 x4f 0 x66 0 x6d 0 x7d 0 x07 0 x7f 0 x6f 0 x40 void main 3 unsigned int i j 1 unsigned int led 10 cnt 0 while 1 進入循環狀態 if cnt 50 cnt 0 延時計數 每掃描一次加一次 j 每隔 50 個掃描周期加一次 led 0 Disp Tab j 10000 1000 0 x80 led 1 Disp Tab j 1000 100 0 x80 led 2 Disp Tab j 100 10 0 x80 led 3 Disp Tab j 10 0 x80 led 4 Disp Tab j 10000 1000 千位 led 5 Disp Tab j 1000 100 百位帶小數點 led 6 Disp Tab j 100 10 十位 led 7 Disp Tab j 10 個位 for i 0 i 0 i for j 200 j 0 j 單片機直接片選實現動態顯示單片機直接片選實現動態顯示 include include void delay unsigned int i 函數聲名 char DelayCNT 定義變量 unsigned char code Disp Tab 共陰數碼管 0 9 0 x3f 0 x06 0 x5b 0 x4f 0 x66 0 x6d 0 x7d 0 x07 0 x7f 0 x6f 0 x40 段碼控制 unsigned char code dispbit 8 共陰數碼管 1 8 個 0 xfe 0 xfd 0 xfb 0 xf7 0 xef 0 xdF 0 xbF 0 x7F 位選控制 查表法 void main unsigned int i LedNumVal 1 變量定義 unsigned int LedOut 10 變量定義 DelayCNT 0 while 1 if DelayCNT 20 控制數字變化速度 DelayCNT 0 20 個掃描周期清零一次 LedNumVal 每隔 20 個掃描周期加一次 LedOut 0 Disp Tab LedNumVal 10000 1000 LedOut 1 Disp Tab LedNumVal 1000 100 0 x80 LedOut 2 Disp Tab LedNumVal 100 10 LedOut 3 Disp Tab LedNumVal 10 LedOut 4 Disp Tab LedNumVal 10000 1000 千位 LedOut 5 Disp Tab LedNumVal 1000 100 0 x80 百位小數 LedOut 6 Disp Tab LedNumVal 100 10 十位 LedOut 7 Disp Tab LedNumVal 10 個位 for i 0 i 0 i for j 200 j 0 j 動態動態 靜態靜態 LED include include sbit LED8 1 P1 1 J14 接在 P1 1 上 void delay unsigned int i 函數聲名 char DelayCNT char LED void main LED 0 x01 DelayCNT 0 while 1 if DelayCNT 10 點亮動靜 LED 燈速度控制 DelayCNT 0 LED LED 0 i for j 200 j 0 j 數碼管數碼管 138 動態顯示動態顯示 include define uint unsigned int define uchar unsigned char sbit LS138A P2 2 sbit LS138B P2 3 sbit LS138C P2 4 uchar code led 8 void delay uint xms uint i j for i xms i 0 i for j 110 j 0 j uchar code table 0 x3f 0 x06 0 x5B 0 x4f 0 x66 0 x6d 0 x7d 0 x07 0 x7f 0 x6f void main while 1 進入循環狀態 uint cnt j LS138A 1 LS138B 1 LS138C 1 if cnt 50 cnt 0 延時計數 每掃描一次加一次 j 每隔 50 個掃描周期加一次 led 0 table j 10000 1000 led 1 table j 1000 100 led 2 table j 100 10 led 3 table j 10 led 4 table j 10000 1000 千位 led 5 table j 1000 100 百位帶小數點 led 6 table j 100 10 十位 led 7 table j 10 個位 數碼管數碼管 依次顯示依次顯示 0 F include unsigned char code table 共陽數碼管 0 x3F 0 x06 0 x5B 0 x4F 0 x66 0 x6D 0 x7D 0 x07 0 x7F 0 x6F 0 x77 0 x7C 0 x39 0 x5E 0 x79 0 x71 void delay unsigned int xms unsigned int i j for i xms i 0 i for j 110 j 0 j void main unsigned char cnt while 1 for cnt 0 cnt 16 cnt P0 table cnt delay 100 數碼管數碼管 直選動態顯示直選動態顯示 include unsigned char code dispiaybit 0 xfe 0 xfd 0 xfb 0 xf7 0 xef 0 xdf 0 xbf 0 x7f unsigned char code table 0 x06 0 x5B 0 x4f 0 x66 0 x6d 0 x7d 0 x07 0 x7f 0 x6f void delay unsigned int xms unsigned int i j for i xms i 0 i for j 110 j 0 j void main unsigned char m while 1 for m 0 m 8 m P0 table m P1 dispiaybit m delay 1 數碼管秒表數碼管秒表 include void delay int xms unsigned int cnt for cnt 0 cnt 250 num cnt 0 一位靜態顯示一位靜態顯示 include include define NOP nop 定義空指令 void delay unsigned int i 函數聲名 unsigned char code LED7Code 共陽極 0 x3F 0 x06 0 x5B 0 x4F 0 x66 0 x6D 0 x7D 0 x07 0 x7F 0 x6F 0 x77 0 x7C 0 x39 0 x5E 0 x79 0 x71 void main unsigned int LedNumVal 1 C 定義變量 while 1 if C 300 LedNumVal 每隔 300 個掃描周期加一次 C 0 每隔 300 個掃描清零 將字模送到 P0 口顯示 P0 LED7Code LedNumVal 10 LED7 0 x7f 為小數點 共陰和共陽此處不一樣 delay 150 調用延時程序 void delay unsigned int i char j for i i 0 i for j 200 j 0 j 3 蜂鳴器蜂鳴器 嘀嘀嘀嘀 include sbit buzz P3 4 main TMOD 0 x01 TH0 1000 256 TL0 1000 256 EA 1 ET0 1 TR0 1 for void T0 irq void interrupt 1 using 1 TH0 300 256 TL0 300 256 buzz buzz PZ 蜂鳴器蜂鳴器 include sbit beep P1 5 void delay unsigned int xms unsigned int i j for i xms i 0 i for j 110 j 0 j void main beep 1 delay 1 beep 0 delay 1 八月桂花八月桂花 本例采用 89C52 晶振為 11 0592MHZ 關于如何編制音樂代碼 其實十分簡單 各位可以看以下代碼 頻率常數即音樂術語中的音調 而節拍常數即音樂術語中的多少拍 include include sbit Beep P1 5 unsigned char n 0 n 為節拍常數變量 unsigned char code music tab 格式為 頻率常數 節拍常 數 頻率常數 節拍常數 0 x18 0 x30 0 x1C 0 x10 0 x20 0 x40 0 x1C 0 x10 0 x18 0 x10 0 x20 0 x10 0 x1C 0 x10 0 x18 0 x40 0 x1C 0 x20 0 x20 0 x20 0 x1C 0 x20 0 x18 0 x20 0 x20 0 x80 0 xFF 0 x20 0 x30 0 x1C 0 x10 0 x18 0 x20 0 x15 0 x20 0 x1C 0 x20 0 x20 0 x20 0 x26 0 x40 0 x20 0 x20 0 x2B 0 x20 0 x26 0 x20 0 x20 0 x20 0 x30 0 x80 0 xFF 0 x20 0 x20 0 x1C 0 x10 0 x18 0 x10 0 x20 0 x20 0 x26 0 x20 0 x2B 0 x20 0 x30 0 x20 0 x2B 0 x40 0 x20 0 x20 0 x1C 0 x10 0 x18 0 x10 0 x20 0 x20 0 x26 0 x20 0 x2B 0 x20 0 x30 0 x20 0 x2B 0 x40 0 x20 0 x30 0 x1C 0 x10 0 x18 0 x20 0 x15 0 x20 0 x1C 0 x20 0 x20 0 x20 0 x26 0 x40 0 x20 0 x20 0 x2B 0 x20 0 x26 0 x20 0 x20 0 x20 0 x30 0 x80 6 0 x20 0 x30 0 x1C 0 x10 0 x20 0 x10 0 x1C 0 x10 0 x20 0 x20 0 x26 0 x20 0 x2B 0 x20 0 x30 0 x20 0 x2B 0 x40 0 x20 0 x15 0 x1F 0 x05 0 x20 0 x10 0 x1C 0 x10 0 x20 0 x20 0 x26 0 x20 0 x2B 0 x20 0 x30 0 x20 0 x2B 0 x40 0 x20 0 x30 0 x1C 0 x10 0 x18 0 x20 0 x15 0 x20 0 x1C 0 x20 0 x20 0 x20 0 x26 0 x40 0 x20 0 x20 0 x2B 0 x20 0 x26 0 x20 0 x20 0 x20 0 x30 0 x30 0 x20 0 x30 0 x1C 0 x10 0 x18 0 x40 0 x1C 0 x20 0 x20 0 x20 0 x26 0 x40 0 x13 0 x60 0 x18 0 x20 0 x15 0 x40 0 x13 0 x40 0 x18 0 x80 0 x00 void int0 interrupt 1 采用中斷 0 控制節拍 TH0 0 xd8 TL0 0 xef n void delay unsigned char m 控制頻率延時 unsigned i 3 m while i void delayms unsigned char a 豪秒延時子程序 while a 采用 while a 不要采用 while a 各位可編譯一下看看匯編結果就知道 了 void main unsigned char p m m 為頻率常數變量 unsigned char i 0 TMOD TMOD 0 x01 TH0 0 xd8 TL0 0 xef IE 0 x82 play while 1 a p music tab i if p 0 x00 i 0 delayms 1000 goto play 如果碰到結束符 延時 1 秒 回到開始再來一遍 else if p 0 xff i i 1 delayms 100 TR0 0 goto a 若碰到休止符 延時 100ms 繼續取下一音符 else m music tab i n music tab i 取頻率常數 和 節拍常數 TR0 1 開定時器 1 while n 0 Beep Beep delay m 等待節拍完成 通過 P1 口輸出音頻 可多聲道 哦 TR0 0 關定時器 1 5 繼電器繼電器 按鍵控制繼電器按鍵控制繼電器 include sbit RELAY P1 4 定義繼電器對應單片機管腳 sbit K1 P2 7 定義按鈕對應單片機管腳 void main if K1 RELAY 0 按鈕按下 開啟繼電器 else RELAY 1 按鈕松開 關閉繼電器 4 按鍵按鍵 模擬開關模擬開關 include sbit K1 P3 0 sbit L1 P2 0 void delay unsigned int i unsigned int j for i i 0 i for j 110 j 0 j void main while 1 if K1 0 delay 100 if K1 0 L1 L1 while K1 按鍵鍵狀態顯示按鍵鍵狀態顯示 include include sbit BEEP P1 5 sbit RELAY P1 4 sbit K1 P0 0 sbit K2 P0 1 sbit K3 P0 2 sbit K4 P0 3 sbit K5 P0 4 sbit K6 P0 5 void beep main while 1 P2 0 xff if K1 0 7 P2 0 xfe if K2 0 P2 0 xfd if K3 P2 0 xfb if K4 P2 0 xf7 if K5 beep 喇叭發聲 RELAY 1 if K6 RELAY 0 通過了反相器 void beep unsigned char i j for i 0 i 100 i BEEP BEEP BEEP 取反 for j 0 j 250 j 需要產生方波 nop BEEP 1 關閉蜂鳴器 按鍵移位按鍵移位 include include void delayms unsigned char ms void proc key unsigned char key v void delayms unsigned char ms unsigned char i while ms for i 0 i 120 i sbit K1 P0 0 對應按鈕 K1 sbit K2 P0 1 對應按鈕 K2 void main unsigned char key s key v key v 0 x03 P2 0 xfe while 1 key s scan key if key s key v delayms 10 key s scan key if key s key v key v key s proc key key v unsigned char scan key unsigned char key s key s 0 x00 key s K2 key s 1 key s K1 return key s void proc key unsigned char key v if key v else if key v 6 定時器定時器 中斷中斷 蜂鈴器蜂鈴器 timer1 include include sbit Beep P1 5 unsigned int USE C void main TMOD 0 x10 定時 計數器 1 工作于方式 1 TH0 0 x4C TL0 0 x00 50ms 定時常數 EA 1 開總中斷 ET1 1 允許定時 計數器 1 中斷 TR1 1 啟動定時 計數器 1 中斷 while 1 void Time1 void interrupt 3 TH1 0 x4c 50ms 定時 TL1 0 x00 if USE C 20 每隔 1 秒發聲 Beep Beep USE C 0 中斷中斷 0 計數計數 1 位數碼管顯示位數碼管顯示 include include unsigned int LedNumVal 此表為 LED 的字模 0 1 2 3 4 5 6 7 8 9 A b c d E L P U Hidden 20 unsigned char code Disp Tab 0 xC0 0 xF9 0 xA4 0 xB0 0 x99 0 x92 0 x82 0 xF8 0 x80 0 x90 0 x88 0 x83 0 xC6 0 xA1 0 x86 0 xbf 0 xc7 0 x8c 0 xc1 0 xff 0 xf7 8 void main void IT0 0 低電平觸發 IT0 1 下降沿觸發 EA 1 EX0 1 while 1 P0 Disp Tab LedNumVal 10 INT0 中斷函數 void counter void interrupt 0 EX0 0 LedNumVal 中斷計數 EX0 1 中斷中斷 0 計數計數 4 位數碼管顯示位數碼管顯示 試驗 4 位數碼管上顯示外部中斷計數 include include sbit LS138A P2 2 sbit LS138B P2 3 sbit LS138C P2 4 unsigned int LedNumVal 0 LedOut 8 此表為 LED 的字模 0 1 2 3 4 5 6 7 8 9 A b c d E L P U Hidden 20 unsigned char code Disp Tab 0 xC0 0 xF9 0 xA4 0 xB0 0 x99 0 x92 0 x82 0 xF8 0 x80 0 x9 0 0 x88 0 x83 0 xC6 0 xA1 0 x86 0 xbf 0 xc7 0 x8c 0 xc1 0 xff 0 xf7 void delay unsigned int i char j for i i 0 i for j 200 j 0 j display unsigned char i LedOut 0 Disp Tab LedNumVal 10000 1000 LedOut 1 Disp Tab LedNumVal 1000 100 LedOut 2 Disp Tab LedNumVal 100 10 LedOut 3 Disp Tab LedNumVal 10 for i 0 i 8 i P0 LedOut i switch i case 0 LS138A 0 LS138B 0 LS138C 0 break case 1 LS138A 1 LS138B 0 LS138C 0 break case 2 LS138A 0 LS138B 1 LS138C 0 break case 3 LS138A 1 LS138B 1 LS138C 0 break case 4 LS138A 0 LS138B 0 LS138C 1 break case 5 LS138A 1 LS138B 0 LS138C 1 break case 6 LS138A 0 LS138B 1 LS138C 1 break case 7 LS138A 1 LS138B 1 LS138C 1 break delay 150 void main void P0 0 xff P1 0 xff P2 0 xff IT0 0 低電平觸發 IT0 1 下降沿觸發 EA 1 EX0 1 while 1 display INT0 中斷函數 void counter void interrupt 0 EX0 0 LedNumVal 中斷計數 EX0 1 INT0 INT1 include include sbit LS138A P2 2 sbit LS138B P2 3 sbit LS138C P2 4 unsigned int LedNumVal 1 LedNumVal 2 LedOut 8 unsigned char code Disp Tab 共陰數碼管 0 9 0 x3f 0 x06 0 x5b 0 x4f 0 x66 0 x6d 0 x7d 0 x07 0 x7f 0 x6f 0 x40 void delay unsigned int i char j for i i 0 i for j 200 j 0 j void main void unsigned char i P0 0 xff P1 0 xff P2 0 xff IT0 0 低電平觸發 IT0 1 下降沿觸發 EX0 1 IT1 0 低電平觸發 IT1 1 下降沿觸發 9 EX1 1 EA 1 while 1 LedOut 0 Disp Tab LedNumVal 1 10000 1000 LedOut 1 Disp Tab LedNumVal 1 1000 100 0 x80 0 x7f 小數點 LedOut 2 Disp Tab LedNumVal 1 100 10 LedOut 3 Disp Tab LedNumVal 1 10 LedOut 4 Disp Tab LedNumVal 2 10000 1000 LedOut 5 Disp Tab LedNumVal 2 1000 100 LedOut 6 Disp Tab LedNumVal 2 100 10 LedOut 7 Disp Tab LedNumVal 2 10 for i 0 i 8 i P0 LedOut i switch i case 0 LS138A 0 LS138B 0 LS138C 0 break case 1 LS138A 1 LS138B 0 LS138C 0 break case 2 LS138A 0 LS138B 1 LS138C 0 break case 3 LS138A 1 LS138B 1 LS138C 0 break case 4 LS138A 0 LS138B 0 LS138C 1 break case 5 LS138A 1 LS138B 0 LS138C 1 break case 6 LS138A 0 LS138B 1 LS138C 1 break case 7 LS138A 1 LS138B 1 LS138C 1 break delay 150 INT0 中斷函數 void counter0 void interrupt 0 EX0 0 delay 100 LedNumVal 1 EX0 1 INT1 中斷函數 void counter1 void interrupt 2 EX1 0 delay 100 LedNumVal 2 EX1 1 T0 數碼管數碼管 include char num unsigned char Led 10 0 x3f 0 x06 0 x5B 0 x4f 0 x66 0 x6d 0 x7d 0 x07 0 x7f 0 x6f void main TMOD 0 x01 EA 1 ET0 1 TR0 1 TH0 65536 45872 256 TL0 65536 45872 256 while 1 void T0 time interrupt 1 TH0 65536 45872 256 TL0 65536 45872 256 num if num 200 num 0 P0 0 x1e P2 Led 1 TIMEER0 試驗數碼管上顯示定時器中斷計數 include include sbit LS138A P2 2 定義 138 管腳 sbit LS138B P2 3 sbit LS138C P2 4 unsigned int LedNumVal LedOut 8 此表為 LED 的字模 0 1 2 3 4 5 6 7 8 9 A b c d E L P U Hidden 20 unsigned char code Disp Tab 0 xC0 0 xF9 0 xA4 0 xB0 0 x99 0 x92 0 x82 0 xF8 0 x80 0 x9 0 0 x88 0 x83 0 xC6 0 xA1 0 x86 0 xbf 0 xc7 0 x8c 0 xc1 0 xff 0 xf7 系統初始化 void system Ini TMOD 0 x11 TH1 0 x1C 12 000M TL1 0 x18 IE 0 x8A TR1 1 void delay unsigned int i char j for i i 0 i for j 200 j 0 j void main system Ini while 1 unsigned char i LedOut 0 Disp Tab LedNumVal 10000 1000 LedOut 1 Disp Tab LedNumVal 1000 100 LedOut 2 Disp Tab LedNumVal 100 10 LedOut 3 Disp Tab LedNumVal 10 for i 0 i 500 計數 500 次 IntCnt 0 SecFlag 1 switch Counter 5 case 1 P0 0 x02 0000 0010 P2 LedSeg Sec 10 break case 2 P0 0 x04 0000 0100 P2 LedSeg Sec 10 break case 3 P0 0 x08 0000 1000 P2 LedSeg Min 10 break case 4 P0 0 x10 0001 0000 P2 LedSeg Min 10 break void InitTime 中斷定時初始化 TMOD 0 x01 GATE C T M1 M0 GATE C T M1 M0 設置為定時器 0 的工作方式 1 0 0 0 0 0 0 0 1 TH0 0 xf8 裝載初值 TL0 0 xcd TCON 0 x10 TF1 TR1 TF0 TR0 0000 控制啟停 0 0 0 1 IE 0 x82 EA 00 ES ET1 EX1 ET0 EX0 中斷允許控制 E enable 1 00 0 0 0 1 0 void main unsigned int Counter 0 bit StopFlag 0 0 Time Run 1 Time Stop InitTime 初始化單片機內部的定時器 以中斷方式工作在 16 位模式 while 1 if StopFlag 0 走時 if SecFlag 計時程序 SecFlag 0 if Sec 59 Sec 0 if Min 59 Min 0 定時器定時器 按鍵按鍵 include reg51 h bit SecFlag 0 sbit TIMESTOP K P1 0 void Delay2ms unsigned int DelayTime 軟件延時 unsigned int Count for Count 0 Count 500 計數 500 次 IntCnt 0 SecFlag 1 switch Counter 5 11 case 1 P0 0 x02 0000 0010 P2 LedSeg Sec 10 break case 2 P0 0 x04 0000 0100 P2 LedSeg Sec 10 break case 3 P0 0 x08 0000 1000 P2 LedSeg Min 10 break case 4 P0 0 x10 0001 0000 P2 LedSeg Min 10 break void InitTime 硬件延時 TMOD 0 x01 GATE C T M1 M0 GATE C T M1 M0 設置為定時器 0 的工作方式 1 0 0 0 0 0 0 0 1 TH0 0 xf8 裝載初值 TL0 0 xcd TCON 0 x10 TF1 TR1 TF0 TR0 0000 控制啟停 0 0 0 1 IE 0 x82 EA 00 ES ET1 EX1 ET0 EX0 E enable 中斷允許控制 1 00 0 0 0 1 0 void main unsigned int Counter 0 bit StopFlag 0 0 Time Run 1 Time Stop InitTime 初始化單片機內部的定時器 以中斷方式工作在 16 位模式 while 1 if StopFlag 0 走時 if SecFlag 計時程序 SecFlag 0 if Sec 59 Sec 0 if Min 59 Min 0 按鍵工作 讓走時停止 StopFlag 1 if TIMESTOP K 0 Delay2ms 5 while TIMESTOP K 0 StopFlag StopFlag 7 LED 點陣點陣 顯示數字顯示數字 LED 點陣實驗 流動顯示 1 2 3 4 5 6 7 8 9 include unsigned char code tab 0 xfe 0 xfd 0 xfb 0 xf7 0 xef 0 xdf 0 xbf 0 x7f unsigned char code digittab 18 8 0 x00 0 x00 0 x3e 0 x41 0 x41 0 x41 0 x3e 0 x00 0 0 x00 0 x00 0 x00 0 x00 0 x21 0 x7f 0 x01 0 x00 1 0 x00 0 x00 0 x27 0 x45 0 x45 0 x45 0 x39 0 x00 2 0 x00 0 x00 0 x22 0 x49 0 x49 0 x49

總結

以上是生活随笔為你收集整理的单片机c语言必背100代码,单片机C语言代码手册 含100多个经典C程序.pdf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。