附件為:LCD12864顯示漢字和數字的程序與電路 /* 自定義延時子函數 */ void delayms(uchar z) { int x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } /* 判斷LCD忙信號狀態 */ void buys() { int dat; RW=1; RS=0; do { P0=0x00; E=1; dat=P0; E=0; dat=0x80 & dat; } wHILE(!(dat==0x00)); } /* LCD寫指令函數 */ void w_com(uchar com) { //buys(); RW=0; RS=0; E=1; P0=com; E=0; } /* LCD寫數據函數 */ void w_date(uchar date) { //buys(); RW=0; RS=1; E=1; P0=date; E=0; } /* LCD選屏函數 */ void select_screen(uchar screen) { switch(screen) { case 0: //選擇全屏 CS1=0; CS2=0; break; case 1: //選擇左屏 CS1=0; CS2=1; break; case 2: //選擇右屏 CS1=1; CS2=0; break; /* case 3: //選擇右屏 CS1=1; CS2=1; break; */ } } /* LCDx向上滾屏顯示 */ void lcd_rol() { int x; for(x=0;x<64;x++) { select_screen(0); w_com(0xc0+x); delayms(500); } } /* LCD清屏函數:清屏從第一頁的第一列開始,總共8頁,64列 */ void clear_screen(screen) { int x,y; select_screen(screen); //screen:0-選擇全屏,1-選擇左半屏,2-選擇右半屏 for(x=0xb8;x<0xc0;x++) //從0xb8-0xbf,共8頁 { w_com(x); w_com(0x40); //列的初始地址是0x40 for(y=0;y<64;y++) { w_date(0x00); } } } /* LCD顯示漢字字庫函數 */ void lcd_display_hanzi(uchar screen,uchar page,uchar col,uint mun) { //screen:選擇屏幕參數,page:選擇頁參數0-3,col:選擇列參數0-3,mun:顯示第幾個漢字的參數 int a; mun=mun*32; select_screen(screen); w_com(0xb8+(page*2)); w_com(0x40+(col*16)); for ( a=0;a<16;a++) { w_date(hanzi[mun++]); } w_com(0xb8+(page*2)+1); w_com(0x40+(col*16)); for ( a=0;a<16;a++) { w_date(hanzi[mun++]); } } /* LCD顯示字符字庫函數 */ void lcd_display_zifuk(uchar screen,uchar page,uchar col,uchar mun) { //screen:選擇屏幕參數,page:選擇頁參數0-3,col:選擇列參數0-7,mun:顯示第幾個漢字的參數 int a; mun=mun*16; select_screen(screen); w_com(0xb8+(page*2)); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(zifu[mun++]); } w_com(0xb8+(page*2)+1); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(zifu[mun++]); } } /* LCD顯示數字字庫函數 */ void lcd_display_shuzi(uchar screen,uchar page,uchar col,uchar mun) { //screen:選擇屏幕參數,page:選擇頁參數0-3,col:選擇列參數0-7,mun:顯示第幾個漢字的參數 int a; mun=mun*16; select_screen(screen); w_com(0xb8+(page*2)); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(shuzi[mun++]); } w_com(0xb8+(page*2)+1); w_com(0x40+(col*8)); for ( a=0;a<8;a++) { w_date(shuzi[mun++]); } } /* LCD初始化函數 */ void lcd_init() { w_com(0x3f); //LCD開顯示 w_com(0xc0); //LCD行初始地址,共64行 w_com(0xb8); //LCD頁初始地址,共8頁 w_com(0x40); //LCD列初始地址,共64列 } /* LCD顯示主函數 */ void main() { //第一行 int x; lcd_init(); //LCD初始化 clear_screen(0); //LCD清屏幕 lcd_display_shuzi(1,0,4,5); //LCD顯示數字 lcd_display_shuzi(1,0,5,1); //LCD顯示數字 lcd_display_hanzi(1,0,3,0); //LCD顯示漢字 lcd_display_hanzi(2,0,0,1); //LCD顯示漢字 //LCD字符漢字 lcd_display_hanzi(2,0,1,2); //LCD顯示漢字 //第二行 lcd_display_zifuk(1,1,2,0); //LCD顯示字符 lcd_display_zifuk(1,1,3,0); //LCD顯示字符 lcd_display_zifuk(1,1,4,0); //LCD顯示字符 lcd_display_zifuk(1,1,5,4); //LCD顯示字符 lcd_display_shuzi(1,1,6,8); //LCD顯示字符 lcd_display_shuzi(1,1,7,9); //LCD顯示字符 lcd_display_shuzi(2,1,0,5); //LCD顯示字符 lcd_display_shuzi(2,1,1,1); //LCD顯示字符 lcd_display_zifuk(2,1,2,4); lcd_display_zifuk(2,1,3,1); lcd_display_zifuk(2,1,4,2); lcd_display_zifuk(2,1,5,3); //第三行 for(x=0;x<4;x++) { lcd_display_hanzi(1,2,x,3+x); //LCD顯示漢字 } for(x=0;x<4;x++) { lcd_display_hanzi(2,2,x,7+x); //LCD顯示漢字 } //第四行 for(x=0;x<4;x++) { lcd_display_zifuk(1,3,x,5+x); //LCD顯示漢字 } lcd_display_shuzi(1,3,4,7); lcd_display_shuzi(1,3,5,5); lcd_display_shuzi(1,3,6,5); lcd_display_zifuk(1,3,7,9); lcd_display_shuzi(2,3,0,8); lcd_display_shuzi(2,3,1,9); lcd_display_shuzi(2,3,2,9); lcd_display_shuzi(2,3,3,5); lcd_display_shuzi(2,3,4,6); lcd_display_shuzi(2,3,5,8); lcd_display_shuzi(2,3,6,9); lcd_display_shuzi(2,3,7,2); wHILE(1); /* wHILE(1) { // LCD向上滾屏顯示 lcd_rol(); } */ }
上傳時間: 2013-11-08
上傳用戶:aeiouetla
TLC2543是TI公司的12位串行模數轉換器,使用開關電容逐次逼近技術完成A/D轉換過程。由于是串行輸入結構,能夠節省51系列單片機I/O資源;且價格適中,分辨率較高,因此在儀器儀表中有較為廣泛的應用。 TLC2543的特點 (1)12位分辯率A/D轉換器; (2)在工作溫度范圍內10μs轉換時間; (3)11個模擬輸入通道; (4)3路內置自測試方式; (5)采樣率為66kbps; (6)線性誤差±1LSBmax; (7)有轉換結束輸出EOC; (8)具有單、雙極性輸出; (9)可編程的MSB或LSB前導; (10)可編程輸出數據長度。 TLC2543的引腳排列及說明 TLC2543有兩種封裝形式:DB、DW或N封裝以及FN封裝,這兩種封裝的引腳排列如圖1,引腳說明見表1 TLC2543電路圖和程序欣賞 #include<reg52.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int sbit clock=P1^0; sbit d_in=P1^1; sbit d_out=P1^2; sbit _cs=P1^3; uchar a1,b1,c1,d1; float sum,sum1; double sum_final1; double sum_final; uchar duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar wei[]={0xf7,0xfb,0xfd,0xfe}; void delay(unsigned char b) //50us { unsigned char a; for(;b>0;b--) for(a=22;a>0;a--); } void display(uchar a,uchar b,uchar c,uchar d) { P0=duan[a]|0x80; P2=wei[0]; delay(5); P2=0xff; P0=duan[b]; P2=wei[1]; delay(5); P2=0xff; P0=duan[c]; P2=wei[2]; delay(5); P2=0xff; P0=duan[d]; P2=wei[3]; delay(5); P2=0xff; } uint read(uchar port) { uchar i,al=0,ah=0; unsigned long ad; clock=0; _cs=0; port<<=4; for(i=0;i<4;i++) { d_in=port&0x80; clock=1; clock=0; port<<=1; } d_in=0; for(i=0;i<8;i++) { clock=1; clock=0; } _cs=1; delay(5); _cs=0; for(i=0;i<4;i++) { clock=1; ah<<=1; if(d_out)ah|=0x01; clock=0; } for(i=0;i<8;i++) { clock=1; al<<=1; if(d_out) al|=0x01; clock=0; } _cs=1; ad=(uint)ah; ad<<=8; ad|=al; return(ad); } void main() { uchar j; sum=0;sum1=0; sum_final=0; sum_final1=0; wHILE(1) { for(j=0;j<128;j++) { sum1+=read(1); display(a1,b1,c1,d1); } sum=sum1/128; sum1=0; sum_final1=(sum/4095)*5; sum_final=sum_final1*1000; a1=(int)sum_final/1000; b1=(int)sum_final%1000/100; c1=(int)sum_final%1000%100/10; d1=(int)sum_final%10; display(a1,b1,c1,d1); } }
上傳時間: 2013-11-19
上傳用戶:shen1230
#include<reg51.h> //包含單片機寄存器的頭文件 /******************************************************* 函數功能:主函數 (C 語言規定必須有也只能有1 個主函數) ********************************************************/ void main(void) { wHILE(1) //無限循環 { P1=0xff; // P1=1111 1111B,熄滅LED P0=P1; // 將 P1 口狀態送入P0 口 P2=P1; // 將 P1 口狀態送入P2 口 P3=P1; // 將 P1 口狀態送入P3 口
上傳時間: 2013-10-26
上傳用戶:離殤
一、 main.c(35): warning: #128-D: loop is not reachable from preceding code 原因,前面有一個wHILE(1){ …….} 二、 main.c(54): warning: #1-D: last line of file ends without a newline 少了一個回車在}之后
上傳時間: 2014-12-26
上傳用戶:sjb555
單片機c語言學習和單片機制作資料: 函數的使用和熟悉 實例3:用單片機控制第一個燈亮 實例4:用單片機控制一個燈閃爍:認識單片機的工作頻率 實例5:將 P1口狀態分別送入P0、P2、P3口:認識I/O口的引腳功能 實例6:使用P3口流水點亮8位LED 實例7:通過對P3口地址的操作流水點亮8位LED 實例8:用不同數據類型控制燈閃爍時間 實例9:用P0口、P1 口分別顯示加法和減法運算結果 實例10:用P0、P1口顯示乘法運算結果 實例11:用P1、P0口顯示除法運算結果 實例12:用自增運算控制P0口8位LED流水花樣 實例13:用P0口顯示邏輯"與"運算結果 實例14:用P0口顯示條件運算結果 實例15:用P0口顯示按位"異或"運算結果 實例16:用P0顯示左移運算結果 實例17:"萬能邏輯電路"實驗 實例18:用右移運算流水點亮P1口8位LED 實例19:用if語句控制P0口8位LED的流水方向 實例20:用swtich語句的控制P0口8位LED的點亮狀態 實例21:用for語句控制蜂鳴器鳴笛次數 實例22:用wHILE語句控制LED 實例23:用do-wHILE語句控制P0口8位LED流水點亮 實例24:用字符型數組控制P0口8位LED流水點亮 實例25: 用P0口顯示字符串常量 實例26:用P0 口顯示指針運算結果 實例27:用指針數組控制P0口8位LED流水點亮 實例28:用數組的指針控制P0 口8 位LED流水點亮 實例29:用P0 、P1口顯示整型函數返回值 實例30:用有參函數控制P0口8位LED流水速度 實例31:用數組作函數參數控制流水花樣 實例32:用指針作函數參數控制P0口8位LED流水點亮 實例33:用函數型指針控制P1口燈花樣 實例34:用指針數組作為函數的參數顯示多個字符串
上傳時間: 2013-10-21
上傳用戶:llandlu
為提高溫度測量效率,降低系統的成本,擴展傳輸距離,設計出一種新型溫度采集系統。單片機通過控制具有單總線方式的溫度傳感器DS18B20實現對溫度的測量,同時單片機通過控制具有單總線方式300~450MHz頻率范圍內的MAX7044與MAX7033無線發射與接收芯片實現溫度數據的無線傳輸。與傳統溫度采集系統相比,該系統利用單總線方式連接,采用無線傳輸方式實現遠距離通信,易于系統的集成與擴展。實驗結果表明,該系統結構簡單、方便移植,能夠同時實現多達上百點溫度的測量與500m范圍的傳輸。 Abstract: To improve the temperature measurement efficiency and reduce system cost,expansion of transmission distance,a new type of temperature acquisition system is designed.Microcontroller controlled temperature sensor DS18B20which has a single-bus achieves temperature measurement,wHILE microcontroller by controlled the MAX7044and MAX7033chip with a single-bus and having300~450MHz radiofrequency to achieve the wireless transmission of temperature data.Compared with conventional temperature acquisition system,the system uses single-bus connected,and uses wireless transmission means to achieve long-distance communications,easy-to-system integration and expansion.The experimental results show that the system is simple,convenient transplantation,and can be implemented in as many as a hundred-point temperature measure-ment and the transmission range of500meters.
上傳時間: 2013-10-29
上傳用戶:515414293
NXP Semiconductor designed the LPC2400 microcontrollers around a 16-bit/32-bitARM7TDMI-S CPU core with real-time debug interfaces that include both JTAG andembedded Trace. The LPC2400 microcontrollers have 512 kB of on-chip high-speedFlash memory. This Flash memory includes a special 128-bit wide memory interface andaccelerator architecture that enables the CPU to execute sequential instructions fromFlash memory at the maximum 72 MHz system clock rate. This feature is available onlyon the LPC2000 ARM Microcontroller family of products. The LPC2400 can execute both32-bit ARM and 16-bit Thumb instructions. Support for the two Instruction Sets meansEngineers can choose to optimize their application for either performance or code size atthe sub-routine level. When the core executes instructions in Thumb state it can reducecode size by more than 30 % with only a small loss in performance wHILE executinginstructions in ARM state maximizes core performance.
上傳時間: 2013-11-15
上傳用戶:zouxinwang
C51 中的關鍵字關鍵字 用途 說明auto 存儲種類說明 用以說明局部變量,缺省值為此break 程序語句 退出最內層循環case 程序語句 Switch 語句中的選擇項char 數據類型說明 單字節整型數或字符型數據const 存儲類型說明 在程序執行過程中不可更改的常量值continue 程序語句 轉向下一次循環default 程序語句 Switch 語句中的失敗選擇項do 程序語句 構成do..wHILE 循環結構double 數據類型說明 雙精度浮點數else 程序語句 構成if..else 選擇結構enum 數據類型說明 枚舉extern 存儲種類說明 在其他程序模塊中說明了的全局變量flost 數據類型說明 單精度浮點數for 程序語句 構成for 循環結構goto 程序語句 構成goto 轉移結構if 程序語句 構成if..else 選擇結構int 數據類型說明 基本整型數long 數據類型說明 長整型數register 存儲種類說明 使用CPU 內部寄存的變量return 程序語句 函數返回short 數據類型說明 短整型數signed 數據類型說明 有符號數,二進制數據的最高位為符號位sizeof 運算符 計算表達式或數據類型的字節數static 存儲種類說明 靜態變量struct 數據類型說明 結構類型數據swicth 程序語句 構成switch 選擇結構typedef 數據類型說明 重新進行數據類型定義union 數據類型說明 聯合類型數據unsigned 數據類型說明 無符號數數據void 數據類型說明 無類型數據volatile 數據類型說明 該變量在程序執行中可被隱含地改變wHILE 程序語句 構成wHILE 和do..wHILE 循環結構ANSIC 標準關鍵字關鍵字 用途 說明bit 位標量聲明 聲明一個位標量或位類型的函數sbit 位標量聲明 聲明一個可位尋址變量
標簽: C51
上傳時間: 2013-10-08
上傳用戶:waves_0801
AT89C2051驅動步進電機的電路和源碼:AT89C2051驅動步進電機的電路和源碼 程序:stepper.c stepper.hex/* * STEPPER.C * sweeping stepper's rotor cw and cww 400 steps * Copyright (c) 1999 by W.Sirichote */#i nclude c:\mc5151io.h /* include i/o header file */ #i nclude c:\mc5151reg.hregister unsigned char j,flag1,temp; register unsigned int cw_n,ccw_n;unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90} #define n 400/* flag1 mask byte 0x01 run cw() 0x02 run ccw() */main(){ flag1=0; serinit(9600); disable(); /* no need timer interrupt */ cw_n = n; /* initial step number for cw */ flag1 |=0x01; /* initial enable cw() */wHILE(1){ { tick_wait(); /* wait for 10ms elapsed */energize(); /* round-robin execution the following tasks every 10ms */ cw(); ccw(); } }}cw(){ if((flag1&0x01)!=0) { cw_n--; /* decrement cw step number */ if (cw_n !=0) j++; /* if not zero increment index j */ else {flag1&=~0x01; /* disable cw() execution */ ccw_n = n; /* reload step number to ccw counter */ flag1 |=0x02; /* enable cww() execution */ } }
上傳時間: 2013-11-21
上傳用戶:boyaboy
The PCA9516 is a BiCMOS integrated circuit intended forapplication in I2C and SMBus systems.wHILE retaining all the operating modes and features of the I2Csystem, it permits extension of the I2C-bus by buffering both the data(SDA) and the clock (SCL) lines, thus enabling five buses of 400 pF.The I2C-bus capacitance limit of 400 pF restricts the number ofdevices and bus length. Using the PCA9516 enables the systemdesigner to divide the bus into five segments off of a hub where anysegment to segment transition sees only one repeater delay.
上傳時間: 2013-11-21
上傳用戶:q123321