51單片機結構簡單,架構體系完備,學習資料豐富,應用領域廣泛。通過對51單片機的學習,可幫助小白實現快速入門電子設計,理解電路系統工作原理,為高級嵌入式芯片的學習及開發打下堅實基礎。
本篇描述
1、51+Proteus8.10;
2、學習ADC0808/0809模擬量檢測、數據轉換、1602顯示驅動;
仿真設計
采用Proteus作為仿真設計工具。Proteus是一款著名的EDA工具(仿真軟件),從原理圖布圖、代碼調試到單片機與外圍電路協同仿真,一鍵切換到PCB設計,真正實現了從概念到產品的完整設計。
軟件設計
采用Keil作為軟件設計工具。Keil提供了包括C編譯器、宏匯編、鏈接器、庫管理和一個功能強大的仿真調試器等在內的完整開發方案,通過一個集成開發環境(μVision)將這些部分組合在一起。
#include#include "SMC1602.h" #include "DATransform.h" #define TIME0H 0x3C #define TIME0L 0xB0 unsigned char uc_Clock=0; //?¨ê±?÷0?D????êy bit b_DATransform=0; void vShowVoltage(unsigned int uiNumber) { unsigned char ucaNumber[3],ucCount; if(uiNumber>999) uiNumber=999; ucaNumber[0]=uiNumber/100; //°?????êy×?μ???????′?è?êy×é?£ ucaNumber[1]=(uiNumber-100*(int)ucaNumber[0])/10; ucaNumber[2]=uiNumber-100*(int)ucaNumber[0]-10*ucaNumber[1]; for(ucCount=0;ucCount<3;ucCount++) { vShowOneChar(ucaNumber[ucCount]+48); //′óê×??μ?????eò?ê?3??£ if(ucCount==0) vShowOneChar('.'); } } void main() { TMOD=0x01; //?¨ê±?÷0£??£ê?1?£ TH0=TIME0H; TL0=TIME0L; TR0=1; //???ˉ?¨ê±?÷?£ ET0=1; //?a?¨ê±?÷?D???£ EA=1; //?a×ü?D?? vdInitialize(); vWriteCMD(0x84); //D′è???ê??eê?μ??·£¨μú?tDDμúò???????£ vShowChar("Voltage:"); vWriteCMD(0xC9); vShowChar("(V)"); while(1) { if(b_DATransform==1) { b_DATransform=0; vWriteCMD(0xC4); vShowVoltage(uiADTransform()); } } } void Time0() interrupt 1 { if(uc_Clock==0) { uc_Clock=5; b_DATransform=1; } else uc_Clock--; TH0=TIME0H; //???′?¨ê±?÷0?£ TL0=TIME0L; }
SMC1602.c
#include"SMC1602.h" void vWriteCMD(unsigned char ucCommand) { vDelay(); //?è?óê±?£ LCDE=1; //è?oó°?£ì£?£????aD′è??üá?×′ì??£ LCDRS=0; LCDRW=0; LCDPORT=ucCommand; //?ùê?3??üá??£ LCDE=0; //×?oó?′DD?üá??£ } void vWriteData(unsigned char ucData) { vDelay(); //?è?óê±?£ LCDE=1; //è?oó°?£ì£?£????aD′è?êy?Y×′ì??£ LCDRS=1; LCDRW=0; LCDPORT=ucData; //?ùê?3?êy?Y?£ LCDE=0; //×?oó??ê?êy?Y?£ } void vShowOneChar(unsigned char ucChar) { switch(ucChar) { case ' ': vWriteData(0x20);break; case '!': vWriteData(0x21);break; case '"': vWriteData(0x22);break; case '#': vWriteData(0x23);break; case '$': vWriteData(0x24);break; case '%': vWriteData(0x25);break; case '&': vWriteData(0x26);break; case '>': vWriteData(0x27);break; case '(': vWriteData(0x28);break; case ')': vWriteData(0x29);break; case '*': vWriteData(0x20);break; case '+': vWriteData(0x2A);break; case '-': vWriteData(0x2D);break; case '/': vWriteData(0x2F);break; case '=': vWriteData(0x3D);break; case '<': vWriteData(0x3E);break; case '?': vWriteData(0x3F);break; case '.': vWriteData(0x2E);break; case ':': vWriteData(0x3A);break; case '0': vWriteData(0x30);break; case '1': vWriteData(0x31);break; case '2': vWriteData(0x32);break; case '3': vWriteData(0x33);break; case '4': vWriteData(0x34);break; case '5': vWriteData(0x35);break; case '6': vWriteData(0x36);break; case '7': vWriteData(0x37);break; case '8': vWriteData(0x38);break; case '9': vWriteData(0x39);break; case 'A': vWriteData(0x41);break; case 'B': vWriteData(0x42);break; case 'C': vWriteData(0x43);break; case 'D': vWriteData(0x44);break; case 'E': vWriteData(0x45);break; case 'F': vWriteData(0x46);break; case 'G': vWriteData(0x47);break; case 'H': vWriteData(0x48);break; case 'I': vWriteData(0x49);break; case 'J': vWriteData(0x4A);break; case 'K': vWriteData(0x4B);break; case 'L': vWriteData(0x4C);break; case 'M': vWriteData(0x4D);break; case 'N': vWriteData(0x4E);break; case 'O': vWriteData(0x4F);break; case 'P': vWriteData(0x50);break; case 'Q': vWriteData(0x51);break; case 'R': vWriteData(0x52);break; case 'S': vWriteData(0x53);break; case 'T': vWriteData(0x54);break; case 'U': vWriteData(0x55);break; case 'V': vWriteData(0x56);break; case 'W': vWriteData(0x57);break; case 'X': vWriteData(0x58);break; case 'Y': vWriteData(0x59);break; case 'Z': vWriteData(0x5A);break; case 'a': vWriteData(0x61);break; case 'b': vWriteData(0x62);break; case 'c': vWriteData(0x63);break; case 'd': vWriteData(0x64);break; case 'e': vWriteData(0x65);break; case 'f': vWriteData(0x66);break; case 'g': vWriteData(0x67);break; case 'h': vWriteData(0x68);break; case 'i': vWriteData(0x69);break; case 'j': vWriteData(0x6A);break; case 'k': vWriteData(0x6B);break; case 'l': vWriteData(0x6C);break; case 'm': vWriteData(0x6D);break; case 'n': vWriteData(0x6E);break; case 'o': vWriteData(0x6F);break; case 'p': vWriteData(0x70);break; case 'q': vWriteData(0x71);break; case 'r': vWriteData(0x72);break; case 's': vWriteData(0x73);break; case 't': vWriteData(0x74);break; case 'u': vWriteData(0x75);break; case 'v': vWriteData(0x76);break; case 'w': vWriteData(0x77);break; case 'x': vWriteData(0x78);break; case 'y': vWriteData(0x79);break; case 'z': vWriteData(0x7A);break; default: break; } } void vShowChar(unsigned char ucaChar[]) { unsigned char ucCount; for(ucCount=0;;ucCount++) { vShowOneChar(ucaChar[ucCount]); if(ucaChar[ucCount+1]=='?') break; } } void vDelay() { unsigned int uiCount; for(uiCount=0;uiCount<250;uiCount++); }
SMC1602.h
#ifndef __SMC1602_H__ #define__SMC1602_H__ #include#define vdInitialize() vWriteCMD(0x01);vWriteCMD(0x38);vWriteCMD(0x0C); //3?ê??ˉ #define LCDRS P3_5 #define LCDRW P3_6 #define LCDE P3_7 #define LCDPORT P0 voidvDelay();//?óê±oˉêy?£ voidvWriteCMD(unsignedcharucCommand);//°?1???üá?D′è?LCD?£ voidvWriteData(unsignedcharucData);//°?1??êy?YD′è?LCD?£ voidvShowOneChar(unsignedcharucChar); voidvShowChar(unsignedcharucaChar[]); #endif
DATransform.c
#include#define START P3_4 //ATART£?ALE?ó?ú?£0->1->0:???ˉAD×a???£ #define EOC P3_3 //×a??íê±?óé0±?1. #define OUTPORT P2 unsigned int uiADTransform() { unsigned int uiResult; START=1; //???ˉAD×a???£ START=0; while(EOC==0); //μè′y×a???áê??£ uiResult=OUTPORT; //3?è?×a???á1??£ uiResult=(100*uiResult)/51; //′|àí?????á1??£ return uiResult; }
DATransform.h
#ifndef __DATRANSFORM_H__ #define__DATRANSFORM_H__ unsignedintuiADTransform(); #endif
-
Proteus
+關注
關注
79文章
1692瀏覽量
106756 -
51單片機
+關注
關注
274文章
5705瀏覽量
124081 -
keil
+關注
關注
68文章
1214瀏覽量
167166 -
顯示驅動
+關注
關注
1文章
68瀏覽量
15023 -
ADC0808
+關注
關注
2文章
52瀏覽量
18526
原文標題:5042-AD0808電壓檢測+1602顯示
文章出處:【微信號:電子開發圈,微信公眾號:電子開發圈】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論