版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、<p> 單片機(jī)原理及應(yīng)用課程設(shè)計(jì)</p><p> 學(xué)院名稱: 計(jì)算機(jī)學(xué)院 </p><p> 專業(yè)班級(jí): 計(jì)算機(jī)1001 </p><p> 學(xué)生姓名: </p><p> 學(xué)生學(xué)號(hào): &l
2、t;/p><p> 指導(dǎo)教師姓名: </p><p> 完成時(shí)間: 2013年7月5日 </p><p> 點(diǎn)陣式液晶顯示屏的顯示程序設(shè)計(jì)</p><p><b> 一、設(shè)計(jì)目的</b></p><p> 1.熟練掌握C51系統(tǒng)仿真開發(fā)
3、系統(tǒng)的應(yīng)用。</p><p> 2.加強(qiáng)單片機(jī)的綜合運(yùn)用能力、提高單片機(jī)的軟件編程和調(diào)試能力,為以后的學(xué)習(xí)和開發(fā)工作打下良好基礎(chǔ)。</p><p> 3.掌握的液晶的工作原理以及應(yīng)用設(shè)計(jì)。</p><p> 4.掌握小系統(tǒng)開發(fā)設(shè)計(jì)的流程以及設(shè)計(jì)思路。</p><p><b> 二、設(shè)計(jì)方案</b></p&g
4、t;<p><b> 1、實(shí)驗(yàn)要求:</b></p><p> 1)字符方式:從下到上滾動(dòng)顯示:“江蘇大學(xué)計(jì)算機(jī)學(xué)院”然后交替顯示:“2013年單片機(jī)課程設(shè)計(jì)”“液晶點(diǎn)陣顯示屏程序設(shè)計(jì)”“作者姓名、班級(jí)、學(xué)號(hào)” </p><p> 2)圖片方式:顯示相應(yīng)圖片(有左、右移,上下卷等多種動(dòng)態(tài)方式 )</p><p> 3)
5、模擬量采樣值顯示(溫度、壓力、電位)</p><p> 4) 其它功能不限,可自由發(fā)揮(時(shí)鐘、秒表、計(jì)算器、菜單等),拓展要求</p><p><b> 2、設(shè)計(jì)思路:</b></p><p> 將程序分成四個(gè)模塊:</p><p> 1.主函數(shù)模塊main.c</p><p> 2.模
6、數(shù)轉(zhuǎn)換模塊ADC.c </p><p> 3.液晶顯示模塊KS0108.c</p><p> 4.測(cè)試模塊test7279.c</p><p> 其中,在main.c中定義一個(gè)功能選擇菜單圖片,包含課設(shè)的簡(jiǎn)介,圖片的變換,模擬量的采集以及計(jì)算器的實(shí)現(xiàn),該菜單功能的切換由按鍵功能來實(shí)現(xiàn)。</p><p> 在KS0108.c中定義了兩
7、張圖片分別來簡(jiǎn)單介紹一下該課程設(shè)計(jì),包含“江蘇大學(xué)計(jì)算機(jī)學(xué)院、2013年單片機(jī)課程設(shè)計(jì)”和“秦佳、計(jì)算機(jī)1001、3100602007”;還定義了字符方式下的“液晶點(diǎn)陣顯示屏程序設(shè)計(jì)”;定義了在ADC中要用到的0-9的數(shù)字以及計(jì)算器中要用到的各種運(yùn)算符。在其中還定義了上移、下移、左移和右移函數(shù)以及計(jì)算器實(shí)現(xiàn)的函數(shù)。</p><p> 在ADC.c中定義了字符形式的“溫度壓力電位”以及將模擬量轉(zhuǎn)換成數(shù)字量的sho
8、wadc函數(shù)。</p><p><b> 程序流程圖:</b></p><p><b> 系統(tǒng)主流程圖</b></p><p><b> 主函數(shù)流程圖</b></p><p><b> 顯示模塊流程圖</b></p><p>
9、;<b> 模數(shù)轉(zhuǎn)換模塊流程圖</b></p><p><b> 主要的源程序及注釋</b></p><p><b> 1、main.c</b></p><p> #include "c8051f020.h" </p><p> #include
10、 <intrins.h> </p><p> void Delay1us(unsigned char us)</p><p><b> {</b></p><p> while (us)</p><p><b> {</b></p><
11、;p> _nop_(); _nop_(); _nop_(); _nop_(); _nop_();</p><p><b> --us;</b></p><p><b> }</b></p><p><b> }</b></p><p> void SYSCLK_
12、Init (void)</p><p><b> {</b></p><p> int i; // delay counter</p><p> OSCXCN = 0x67; // start external oscillator wit
13、h</p><p> // 18.432MHz crystal</p><p> for (i=0; i < 256; i++) ; // Wait for osc. to start up</p><p> while (!(OSCXCN & 0x80)) ; // Wait for crystal osc
14、. to settle</p><p> OSCICN = 0x88; // select external oscillator as SYSCLK</p><p> // source and enable missing clock</p><p> // detector</p><p>
15、; //OSCICN = 0x07; //interal 16MHZ</p><p><b> }</b></p><p> #define PRT0CF P0MDOUT</p><p> #define PRT1CF P1MDOUT</p><p> #define PRT2CF P2MDOUT<
16、/p><p> void PORT_Init (void)</p><p><b> {</b></p><p> XBR0 = 0x07; // Enable SMBus, SPI0, and UART0</p><p> XBR1 = 0x00;</p&g
17、t;<p> XBR2 = 0x44; // Enable crossbar and weak pull-ups</p><p> EMI0CF = 0x27;</p><p> EMI0TC = 0x21;</p><p> P74OUT = 0xFF;</p><p&g
18、t; P0MDOUT = 0x15;</p><p> P1MDOUT |= 0x3C; //P1.2-P1.5推挽輸出</p><p> P1 &= 0xc3;//P1.2-P1.5=0</p><p><b> }</b></p><p> void SPI0_Init (
19、void)</p><p><b> {</b></p><p> SPI0CFG = 0x07; // data sampled on 1st SCK rising edge</p><p> // 8-bit data words</p><p> SPI0CFG|=0
20、xC0;//CKPOL =1;</p><p> SPI0CN = 0x03; // Master mode; SPI enabled; flags</p><p> // cleared</p><p> SPI0CKR = SYSCLK/2/8000000-1; // SPI clock <=
21、8MHz (limited by </p><p> // EEPROM spec.)</p><p><b> }</b></p><p> unsigned char Count1ms;</p><p> void Timer0_Init (void)</p><p><b>
22、; {</b></p><p> CKCON|=0x8;</p><p> TMOD|=0x1; //16Bit</p><p> Count1ms=10;</p><p> TR0 = 0; // STOP Timer0</p><p>
23、 TH0 = (-SYSCLK/1000) >> 8; // set Timer0 to overflow in 1ms</p><p> TL0 = -SYSCLK/1000;</p><p> TR0 = 1; // START Timer0</p><p> IE|= 0x2; </p><p>&l
24、t;b> }</b></p><p> void Timer0_ISR (void) interrupt 1 //1ms</p><p><b> {</b></p><p> TH0 = (-SYSCLK/1000) >> 8; </p><p> TL0 = -SYSCLK
25、/1000;</p><p> if (Count1ms) Count1ms--;</p><p><b> }</b></p><p> void Delay1ms(unsigned char T)</p><p><b> {</b></p><p> Coun
26、t1ms=T;</p><p> while (Count1ms);</p><p><b> }</b></p><p> void Delay1s(unsigned char T)</p><p><b> {</b></p><p><b> whi
27、le (T)</b></p><p><b> {</b></p><p> Delay1ms(200);</p><p> Delay1ms(200);</p><p> Delay1ms(200);</p><p> Delay1ms(200);</p>&
28、lt;p> Delay1ms(200);</p><p><b> T--;</b></p><p><b> }</b></p><p><b> }</b></p><p> char GetKeyValue(void);</p><p&
29、gt; void Show(void);</p><p> void Show1(void);</p><p> void showadc();</p><p> void caculater();</p><p> void DispBmp(char *buf);</p><p> void InitLC
30、D(void);</p><p> void WaitKeyOff(void);</p><p> char code screen[]={//功能選擇</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><
31、;p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xC0,0xC0,</p><p> 0xC0,0x40,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0
32、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,
33、0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00
34、,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x41,0x7F,0x7F,0x40,0x00,0x00,0x30,0x70,0x60,0x40,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0xF
35、F,0xFF,0x7F,0x7F,0x7F,0xFB,0xFF,</p><p> 0xFE,0x00,0x00,0x10,0x18,0xDC,0xEE,0x7F,0x1B,0xFD,0xFF,0x06,0x0C,0x0C,0x08,0x08,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
36、00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0
37、x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p>
38、<p> 0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x10,0xF0,0xF0,0x60,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0xF0,0x70,0xF1,</p><p> 0
39、xF1,0xF0,0x00,0x00,0x00,0x00,0xF0,0xF0,0xE0,0x79,0x79,0x58,0x40,0x00,0x00,0x00,</p><p> 0x00,0xA0,0xA0,0xE0,0xF8,0xF8,0xF0,0xD0,0xD0,0x90,0x00,0x00,0x80,0xC0,0xF8,0xF0,</p><p> 0xC0,0xF0,0xF0,
40、0xF0,0xA0,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00
41、,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x0C,0x0E,0x0F,0x0
42、B,0x0C,0x0C,0x00,0x06,0x0E,0x0C,0x08,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x1F,0x0F,0x0F,0x0F,0x0F,0x09,0x3F,</p><p> 0x3F,0x1F,0x00,0x00,0x10,0x18,0x0F,0x07,0x03,0x01,0x3F,0x
43、3F,0x00,0x00,0x00,0x00,</p><p> 0x10,0x11,0x13,0x1E,0x0F,0x0F,0x1F,0x11,0x10,0x10,0x10,0x04,0x04,0x16,0x1F,0x1F,</p><p> 0x17,0x1F,0x0F,0x1F,0x13,0x12,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0
44、x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</
45、p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x04,0x26,0x32,0x3E,0xFE,0xE0,0x00,0xC0,0xC0,0x80,0x00,</p><p&g
46、t; 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0xE8,0xFF,0xFF,0xAC,0xBE,0xFE,0xFF,0xFF,</p><p> 0x7B,0x4A,0x40,0x80,0x90,0xD8,0xFF,0xFE,0xF8,0xF4,0x6C,0xEC,0xFC,0xBC,0x00,0x00,</p><p> 0x10,0x10,
47、0x32,0xFE,0xFE,0xFE,0xFE,0xFE,0x1A,0x08,0x08,0x00,0x00,0x20,0xAC,0xEE,</p><p> 0xFE,0xFF,0xFF,0xB7,0x92,0x00,0x00,0x00,0x90,0xF1,0xFF,0xFE,0xFA,0xF6,0xFE,0xFF,</p><p> 0x6B,0x4A,0x40,0x40,0x60
48、,0xF8,0xFE,0x06,0xFA,0xFC,0xFE,0xF6,0xF4,0x04,0x00,0x00,</p><p> 0x00,0x42,0xCE,0xFE,0xFE,0xFE,0xFE,0xFE,0x66,0x20,0x00,0x00,0x20,0xA0,0xE4,0x64,</p><p> 0xF4,0xF6,0xD2,0xD2,0xD0,0x90,0x10,0x0
49、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x81,0xC1,0xC1,0x00,0x00,0x00,0x01,0x01,0x01,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x
50、E3,0xE2,0x03,0x83,0x81,0x83,</p><p> 0xC3,0xC2,0x02,0x00,0x00,0xC3,0xC3,0xC3,0xE1,0xE3,0xE3,0x21,0x00,0x01,0x01,0x00,</p><p> 0x80,0x82,0x82,0x82,0x83,0x03,0xE3,0xE3,0x03,0x02,0x00,0x00,0x03,0
51、x83,0xC1,0xC0,</p><p> 0xE7,0xE7,0xC0,0x81,0x81,0x01,0x01,0x01,0x01,0x07,0x07,0x03,0x00,0x00,0x07,0x07,</p><p> 0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x06,0x07,0x03,0x03,0x03,0x03,0x02,0x02,0x00,
52、</p><p> 0x02,0x02,0x03,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x02,</p><p> 0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p>&l
53、t;p> 0x00,0x00,0x00,0x00,0x00,0x0C,0x0E,0x0B,0x3F,0x3F,0x08,0x08,0x18,0x38,0x30,0x20,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x12,0x5A,0x7F,0x7F,0x1D,0x3E,0x3F,0x37,</p><p> 0x3C,
54、0x1C,0x04,0x40,0x70,0x3F,0xCF,0xFF,0x7F,0x7F,0x3F,0x7D,0x4C,0x44,0x40,0x08,</p><p> 0x08,0x4C,0x4F,0x67,0x36,0x1E,0x6F,0x79,0x7F,0x0F,0x00,0x00,0xC3,0xFF,0xFD,0xFD,</p><p> 0xFD,0x7F,0x7F,0x4E
55、,0x66,0x72,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x0
56、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
57、00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0
58、x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
59、0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p>
60、;<p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};</p><p> void Choose(){</p><p><b> char i;</b></p><p> InitLCD();</
61、p><p> DispBmp(screen);</p><p><b> for(;;){</b></p><p><b> do{</b></p><p> i=GetKeyValue();</p><p> }while(i==-1);</p><
62、;p> WaitKeyOff();</p><p> if(i==0x01){</p><p><b> Show();</b></p><p><b> }</b></p><p> else if(i==0x02){</p><p><b>
63、Show1();</b></p><p><b> }</b></p><p> if(i==0x03){</p><p> showadc();</p><p><b> }</b></p><p> else if(i==0x04){</p&g
64、t;<p> caculater();</p><p><b> }</b></p><p><b> break;</b></p><p><b> }</b></p><p><b> }</b></p><
65、p> void TestLCD(void);</p><p> void init_adc(void); </p><p> void main (void) </p><p><b> {</b></p><p> WDTCN = 0xde;</p><p> WDTCN =
66、0xad; //關(guān)看門狗</p><p> SYSCLK_Init (); //初始化時(shí)鐘</p><p> Timer0_Init();//初始化定時(shí)器</p><p> PORT_Init (); //初始化IO口</p><p> SPI0_Init ();
67、 //初始化SPI0</p><p> init_adc(); //初始化adc </p><p> CPT1CN|=0x80;//使能比較器1</p><p> REF0CN = 0x03; //使能片內(nèi)參考電壓</p><p> DAC0CN |= 0x80;//使能DAC0</p>
68、;<p> DAC0H=0;DAC0L=0;</p><p> EA=1;//開中斷</p><p><b> for(;;){</b></p><p><b> Choose();</b></p><p><b> }}</b></p
69、><p><b> 2、ADC.c</b></p><p> #include "c8051F020.h"</p><p> #include <intrins.h></p><p> #define MUX_TEMP0x08</p><p> #def
70、ine MUX_VOLT0x01</p><p> #define MUX_PRESS0x02</p><p> unsigned int idata Temp, Press, Volt;</p><p> unsigned char idata mux_select;</p><p> sfr16 ADC0
71、= 0xbe; // ADC0 data</p><p> /*-- 文字: 溫度壓力電位 --*/</p><p> char code wen[]={</p><p> 0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0
72、x00,</p><p> 0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,</p><p> 0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,</p>
73、<p> 0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,</p><p> 0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,</p><p> 0
74、x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,</p><p> 0x00,0xC0,0x30,0xEC,0x03,0x2A,0xC8,0x09,0x0A,0x0E,0x08,0xE8,0x48,0x08,0x00,0x00,</p><p> 0x01,0x00,0x00,
75、0x7F,0x20,0x20,0x20,0x27,0x20,0x30,0x2E,0x21,0x20,0x20,0x20,0x00,</p><p> 0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0x62,0x42,0x02,0x00,</p><p> 0x20,0x18,0x27,0x20,0x20,0x20
76、,0x20,0x20,0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00,</p><p> 0x00,0x10,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,</p><p> 0x00,0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x0
77、0,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,};</p><p> void init_adc(void)</p><p><b> {</b></p><p> ADC0CN = 0x81; // ADC0 enabled; normal tracking</
78、p><p> // mode; ADC0 conversions are initiated </p><p> // on write to AD0BUSY; ADC0 data is</p><p> // left-justified</p><p> REF0CN = 0x07; // e
79、nable temp sensor, on-chip VREF,</p><p> // and VREF output buffer</p><p> mux_select = MUX_TEMP; // CPU on-chip temp sensor</p><p> AMX0SL = MUX_TEMP; </p><p>
80、; ADC0CF = (SYSCLK/2500000) << 3; // ADC conversion clock = 2.5MHz</p><p> //ADC0CF |= 0x01; // PGA gain = 2</p><p> EIE2 &= ~0x02; // d
81、isable ADC0 EOC interrupt</p><p> EIE1 &= ~0x04; // disable ADC0 window compare interrupt</p><p><b> }</b></p><p> void read_analog_inputs(vo
82、id)</p><p><b> {</b></p><p> long temp_long;</p><p> AD0INT = 0; // clear conversion complete indicator</p><p> AD0BUSY = 1;
83、 // initiate conversion</p><p> while (AD0INT == 0); // wait for conversion complete</p><p> switch (mux_select)</p><p><b> {</b></p>
84、<p> case MUX_TEMP:</p><p> temp_long = ADC0 - 42380/2;</p><p> temp_long = (temp_long * 200L) / 156;</p><p> Temp=temp_long;</p><p> AMX0SL = MUX_VOLT;// S
85、elect AIN1 for next read</p><p> mux_select = MUX_VOLT;</p><p><b> break;</b></p><p> case MUX_VOLT:</p><p> temp_long = ADC0;</p><p> Vol
86、t = 24*temp_long/655;</p><p> AMX0SL = MUX_PRESS;// Select on-chip temp sensor</p><p> mux_select = MUX_PRESS;</p><p><b> break;</b></p><p> case MUX_
87、PRESS:</p><p> temp_long = ADC0;</p><p> temp_long = 24*temp_long/655;</p><p> Press = temp_long;</p><p> AMX0SL = MUX_TEMP; </p><p> mux_select = MU
88、X_TEMP;</p><p><b> break;</b></p><p><b> default:</b></p><p> AMX0SL = MUX_TEMP;</p><p> mux_select = MUX_TEMP;</p><p><b>
89、; break;</b></p><p><b> }</b></p><p><b> }</b></p><p> unsigned int GetADCValue(char No)</p><p><b> {</b></p><
90、p> read_analog_inputs();</p><p> read_analog_inputs();</p><p> read_analog_inputs();</p><p> switch (No)</p><p><b> {</b></p><p><b&
91、gt; case 1:</b></p><p> return Temp; //溫度</p><p><b> case 2:</b></p><p> return Volt; //電位</p><p><b> case 3:</b></p><p&
92、gt; if (Press<10) Press=0; //壓力</p><p> return Press;</p><p><b> }</b></p><p><b> }</b></p><p> void shownum(char x,char y,char num); &
93、lt;/p><p> char GetKeyValue(void);</p><p> void LCD_WriteHZ(char x,char y,char *Dot);</p><p> void InitLCD(void);</p><p> void Delay1ms(unsigned char T);</p>&l
94、t;p> void WaitKeyOff(void);</p><p> void showadc(){</p><p> unsigned int w;</p><p> char i,a,flag;</p><p> char buf[4];</p><p><b> flag=0;&l
95、t;/b></p><p><b> for(;;){</b></p><p><b> do{</b></p><p><b> if(flag){</b></p><p> w = GetADCValue(flag);</p><p>
96、 Delay1ms(250);</p><p> buf[0]=(w%10000)/1000;</p><p> buf[1]=(w%1000)/100;</p><p> buf[2]=(w%100)/10;</p><p> buf[3]=(w%10);</p><p> for(a=0;a<4;
97、a++){</p><p> shownum(48+16*a,2,buf[a]);</p><p><b> }</b></p><p><b> }</b></p><p> i=GetKeyValue();</p><p> }while(i==-1);<
98、/p><p> WaitKeyOff();</p><p> InitLCD(); </p><p> switch(i){</p><p><b> case 4: </b></p><p> LCD_WriteHZ(10,2,wen);LCD_WriteHZ(28,2,wen+32);&
99、lt;/p><p><b> flag=1;</b></p><p><b> break;</b></p><p><b> case 5: </b></p><p> LCD_WriteHZ(10,2,wen+32*2);LCD_WriteHZ(28,2,wen+32*
100、3);</p><p><b> flag=2;</b></p><p><b> break;</b></p><p><b> case 6: </b></p><p> LCD_WriteHZ(10,2,wen+32*4);LCD_WriteHZ(28,2,wen
101、+32*5);</p><p><b> flag=3;</b></p><p><b> break;</b></p><p> default:return;</p><p><b> }</b></p><p><b> }}&
102、lt;/b></p><p> 3、KS0108.c</p><p> #include "c8051F020.h"</p><p> #include <intrins.h></p><p> #define LCD_DATA P2</p><p> #define L
103、CD_RS P30</p><p> #define LCD_RW P31</p><p> #define LCD_E P32</p><p> #define LCD_CS1 P33</p><p> #define LCD_CS2 P34</p><p> #define LCD_RST P35
104、</p><p> void Delay1ms(unsigned char);</p><p> /*-- 寬度x高度=128x64 --*/</p><p> char code screen1[]={//江蘇大學(xué)計(jì)算機(jī)學(xué)院、2013年單片機(jī)課程設(shè)計(jì)</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,
105、0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
106、,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
107、0,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
108、00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0xA4,0x70,0x04,0x04,0x04,0xFC,0x04,</p
109、><p> 0x04,0x04,0x00,0x00,0x04,0x24,0xA4,0x2E,0x24,0xF4,0x24,0x2E,0xE4,0x84,0x04,0x00,</p><p> 0x10,0x10,0x10,0x10,0x90,0x7E,0x90,0x10,0x10,0x18,0x10,0x00,0x38,0x08,0x2A,0x2C,</p><p>
110、; 0x2A,0xAC,0x68,0x28,0x0E,0x28,0x18,0x00,0x20,0xE2,0x04,0x00,0x20,0x20,0x20,0xFE,</p><p> 0x20,0x20,0x20,0x00,0x10,0x0C,0xF6,0x5C,0x54,0x58,0x54,0x56,0xFC,0x04,0x04,0x00,</p><p> 0x08,0xC8,0
111、xFE,0x48,0x88,0xFC,0x04,0x04,0xFE,0x04,0x00,0x00,0x38,0x08,0x2A,0x2C,</p><p> 0x2A,0xAC,0x68,0x28,0x0E,0x28,0x18,0x00,0xFE,0x02,0x1A,0xE6,0x4C,0x54,0xD4,0x56,</p><p> 0xD4,0x54,0x4C,0x00,0x00,
112、0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x0F,0x08,0x08,0x08,0x08,0x0F,0x08,</p><p> 0x08,0x08,0x08,0x00,0x00,0x09,0x08,0x04
113、,0x03,0x08,0x08,0x0C,0x03,0x00,0x03,0x00,</p><p> 0x08,0x08,0x04,0x02,0x01,0x00,0x01,0x02,0x04,0x08,0x08,0x00,0x01,0x01,0x01,0x09,</p><p> 0x09,0x0F,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x0F,0x0
114、4,0x02,0x00,0x00,0x00,0x0F,</p><p> 0x00,0x00,0x00,0x00,0x04,0x04,0x0D,0x07,0x05,0x05,0x05,0x0F,0x05,0x04,0x04,0x00,</p><p> 0x03,0x00,0x0F,0x08,0x04,0x03,0x00,0x00,0x0F,0x08,0x0E,0x00,0x01,0x
115、01,0x01,0x09,</p><p> 0x09,0x0F,0x01,0x01,0x01,0x01,0x01,0x00,0x0F,0x01,0x01,0x09,0x08,0x04,0x03,0x00,</p><p> 0x0F,0x08,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,&
116、lt;/p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><
117、;p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0
118、x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,
119、0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x00
120、,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,</p><p> 0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x08,0x08,0x88,0x70,0x00,0x00,0xF0,0x08,0x08,</p><p> 0x08,0xF0,0x00,0x00,0x00,0x10,0xF8,0x00,0x00,0x0
121、0,0x00,0x10,0x08,0x48,0x48,0xB0,</p><p> 0x00,0x20,0x10,0xCE,0x48,0x48,0x48,0xF8,0x48,0x48,0x48,0x4C,0x08,0x00,0x00,0x00,</p><p> 0x00,0xF8,0x2A,0x2C,0xF8,0x28,0x2C,0x2A,0xF8,0x00,0x00,0x00,0x
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 單片機(jī)課程設(shè)計(jì)---點(diǎn)陣式液晶顯示屏的顯示程序設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)報(bào)告——點(diǎn)陣式液晶顯示屏的顯示程序設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)---液晶點(diǎn)陣顯示屏程序設(shè)計(jì)
- 課程設(shè)計(jì)--點(diǎn)陣式lcd液晶顯示屏設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)---點(diǎn)陣電子顯示屏設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)--點(diǎn)陣led電子顯示屏
- 單片機(jī)課程設(shè)計(jì)---點(diǎn)陣led電子顯示屏
- 液晶顯示屏lcd顯示接口設(shè)計(jì)課程設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)---led點(diǎn)陣電子顯示屏的設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)之led點(diǎn)陣電子顯示屏設(shè)計(jì)
- led顯示屏單片機(jī)課程設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)報(bào)告--- led點(diǎn)陣動(dòng)態(tài)顯示屏設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)--漢字液晶顯示器顯示
- 單片機(jī)課程設(shè)計(jì)lcd顯示屏設(shè)計(jì)
- 基于單片機(jī)的led點(diǎn)陣顯示屏設(shè)計(jì)
- tft液晶顯示屏原理
- 基于單片機(jī)的點(diǎn)陣led顯示屏的原理
- led點(diǎn)陣顯示屏課程設(shè)計(jì)
- 液晶課程設(shè)計(jì)--單片機(jī)液晶顯示器系統(tǒng)設(shè)計(jì)
- 單片機(jī)課程設(shè)計(jì)--時(shí)鐘及液晶顯示器設(shè)計(jì)
評(píng)論
0/150
提交評(píng)論