郭天祥視頻教程完整C程序_第1頁
郭天祥視頻教程完整C程序_第2頁
郭天祥視頻教程完整C程序_第3頁
郭天祥視頻教程完整C程序_第4頁
郭天祥視頻教程完整C程序_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、 Lesson1 1 #include<reg52.h> sbit D2=P12; unsigned int a; void main() D2=0; /* for(a=0;a<=10000;a+); D2=1; for(a=0;a<=10000;a+);*/ 2 #include<reg52.h> void main() P1=0xfd; lesson2 1 #include<reg52.h> sbit p1_1=P10 unsigned int a void main() while(1) a=51000; p1_1=0; while(a-)

2、; a=51000; while(a-); p1_1=1; a=51000; while(a-); a=51000; while(a-); 2 #include<reg52.h> #define uint unsigned int #define uchar unsigned char sbit D1=P10; /void delay(); void delay(uint); void main() while(1) D1=0; delay(100); D1=1; delay(100); /* void delay() uint x,y; for(x=100;x>0;x-)

3、for(y=600;y>0;y-); */ void delay(uint z) uint x; uchar y; for(x=z;x>0;x-) for(y=20;y>0;y-); lesson3 1 #include<reg52.h> sbit dula=P26; sbit wela=P27; void main() wela=1; P0=0xc0; wela=0; dula=1; P0=0x06; dula=0; while(1); 2 #include<reg52.h> #define uint unsigned int #define uch

4、ar unsigned char sbit dula=P26; sbit wela=P27; uchar num; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71; void delay(uint z); void main() wela=1;/11101010 P0=0xea; wela=0; while(1) for(num=0;num<16;num+) dula=1; P0=tablenum; dula=0; delay(1000

5、); void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); 3 #include<reg52.h> #define uint unsigned int #define uchar unsigned char sbit dula=P26; sbit wela=P27; sbit d1=P10; uchar num; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x

6、79,0x71; void delay(uint z); void main() EA=1;/開總中斷 EX0=1;/開外部中斷0 /IT0=1; TCON=0x01; wela=1;/11101010 P0=0xea; wela=0; while(1) for(num=0;num<16;num+) d1=1; dula=1; P0=tablenum; dula=0; delay(1000); void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); void exter0() interrupt 0 d1

7、=0; 4 #include<reg52.h> #define uint unsigned int #define uchar unsigned char sbit dula=P26; sbit wela=P27; sbit d1=P10; uchar num,num1;tt; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71; void delay(uint z); void main() num=0; tt=0; TMOD=0x

8、11;/設置定時器0為工作方式1 TH0=(65536-10000)/256; TL0=(65536-10000)%256; TH1=(65536-20000)/256; TL1=(65536-20000)%256; / EA=1;/開總中斷 ET0=1;/開定時器0中斷 ET1=1; TR0=1;/啟動定時器0 TR1=1; wela=1;/11101010 P0=0xea; wela=0; dula=1; P0=0x3f; dula=0; while(1) if(num1=25) num1=0; P1=P1; if(tt=100) tt=0; num+; if(num=16) num=0;

9、 dula=1; P0=tablenum; dula=0; void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); void time0() interrupt 1 TH0=(65536-10000)/256; TL0=(65536-10000)%256; tt+; void time1() interrupt 3 TH1=(65536-20000)/256; TL1=(65536-20000)%256; num1+; Lesson4-1 #include<reg52.h> #include<

10、intrins.h> #define uint unsigned int #define uchar unsigned char uchar temp,aa,num; sbit dula=P26; sbit wela=P27; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71; void delay(uint z); void main() num=0; aa=0; TMOD=0x01; TH0=(65536-50000)/256; TL

11、0=(65536-50000)%256; EA=1; ET0=1; TR0=1; temp=0xfe; P1=temp; dula=1; P0=table0; dula=0; wela=1; P0=0xc0; wela=0; while(1) delay(1000); temp=_crol_(temp,1); P1=temp; /* if(aa=40) aa=0; num+; if(num=16) num=0; dula=1; P0=tablenum; dula=0; */ void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y&

12、gt;0;y-); void timer0() interrupt 1 TH0=(65536-50000)/256; TL0=(65536-50000)%256; aa+; if(aa=40) aa=0; num+; if(num=16) num=0; dula=1; P0=tablenum; dula=0; Lesson4-2 #include<reg52.h> #include<intrins.h> #define uint unsigned int #define uchar unsigned char uchar temp,aa,numdu,numwe; sbi

13、t dula=P26; sbit wela=P27; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71; uchar code tablewe= 0xfe,0xfd,0xfb,0xf7,0xef,0xdf; /void delay(uint z); void main() numdu=0; numwe=0; aa=0; TMOD=0x01; TH0=(65536-5000)/256; TL0=(65536-5000)%256; EA=1; ET

14、0=1; TR0=1; while(1) / delay(1000); / temp=_crol_(temp,1); / P1=temp; if(aa=1) aa=0; numdu+; if(numdu=7) numdu=1; dula=1; P0=tablenumdu; dula=0; wela=1; P0=tablewenumwe; wela=0; numwe+; if(numwe=6) numwe=0; /* void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); */ void timer0() int

15、errupt 1 TH0=(65536-5000)/256; TL0=(65536-5000)%256; aa+; Lesson4-3 #include<reg52.h> #define uint unsigned int #define uchar unsigned char uchar temp,aa,bai,shi,ge; sbit dula=P26; sbit wela=P27; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x

16、71; void display(uchar bai,uchar shi,uchar ge); void delay(uint z); void init(); void main() init();/初始化子程序 while(1) if(aa=20) aa=0; temp+; if(temp=100) temp=0; bai=temp/100; shi=temp%100/10; ge=temp%10; display(bai,shi,ge); void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); void

17、display(uchar bai,uchar shi,uchar ge) dula=1; P0=tablebai; dula=0; P0=0xff; wela=1; P0=0xfe; wela=0; delay(1); dula=1; P0=tableshi; dula=0; P0=0xff; wela=1; P0=0xfd; wela=0; delay(1); dula=1; P0=tablege; dula=0; P0=0xff; wela=1; P0=0xfb; wela=0; delay(1); void init() wela=0; dula=0; temp=0; TMOD=0x0

18、1; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; void timer0() interrupt 1 TH0=(65536-50000)/256; TL0=(65536-50000)%256; aa+; Lesson5-1 #include <reg52.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int sbit dula=P26; sbit wela=P27; uchar co

19、de table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71, 0x76,0x79,0x38,0x3f,0; uchar temp,t0,t1,bai,shi,ge,flag,flag1; uint shu; void init(); void display(uchar,uchar,uchar,uchar,uchar,uchar); void delay(uint z) uint t1,y; for(t1=z;t1>0;t1-) for(y=110;y>0;

20、y-); void main() init(); while(1) if(flag1!=1) display(7,6,5,bai,shi,ge); else display(16,17,18,18,19,20); void init() shu=432; temp=0xfe; P1=temp; TMOD=0x11; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TH1=(65536-50000)/256; TL1=(65536-50000)%256; EA=1; ET0=1; ET1=1; TR0=1; TR1=1; void timer0() i

21、nterrupt 1 TH0=(65536-50000)/256; TL0=(65536-50000)%256; t0+; if(flag!=1) if(t0=10) t0=1; temp=_crol_(temp,1); P1=temp; else if(t0%4=0) P1=P1; if(t0=60) TR0=0; P1=0xff; flag1=1; void timer1() interrupt 3 TH1=(65536-50000)/256; TL1=(65536-50000)%256; t1+; if(t1=2) t1=0; shu-; bai=shu/100; shi=shu%100

22、/10; ge=shu%10; if(shu=398) TR0=0; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TR0=1; flag=1; t0=0; P1=0xff; TR1=0; void display(uchar aa,uchar bb,uchar cc,uchar ba,uchar sh,uchar g) dula=1; P0=tableaa; dula=0; P0=0xff; wela=1; P0=0xfe; wela=0; delay(1); dula=1; P0=tablebb; dula=0; P0=0xff; wela=1

23、; P0=0xfd; wela=0; delay(1); dula=1; P0=tablecc; dula=0; P0=0xff; wela=1; P0=0xfb; wela=0; delay(1); dula=1; P0=tableba; dula=0; P0=0xff; wela=1; P0=0xf7; wela=0; delay(1); dula=1; P0=tablesh; dula=0; P0=0xff; wela=1; P0=0xef; wela=0; delay(1); dula=1; P0=tableg; dula=0; P0=0xff; wela=1; P0=0xdf; we

24、la=0; delay(1); Lesson5-2 #include<reg52.h> #define uint unsigned int #define uchar unsigned char sbit d1=P10; sbit dula=P26; sbit wela=P27; sbit key1=P34; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71; uchar num; void delay(uint z) uint x

25、,y; for(x=z;x>0;x-) for(y=110;y>0;y-); void main() wela=1; P0=0xfe; wela=0; P3=0xff; while(1) if(key1=0) delay(5); if(key1=0) d1=0; num+; if(num=10) num=0; while(!key1); delay(5); while(!key1); else d1=1; dula=1; P0=tablenum; dula=0; Lesson5-3 #include<reg52.h> #define uint unsigned int

26、#define uchar unsigned char sbit dula=P26; sbit wela=P27; sbit key1=P34; uchar code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71,0; uchar num,temp,num1; void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); uchar keyscan(); void display(uc

27、har aa); void main() num=17; dula=1; P0=0; dula=0; wela=1; P0=0xc0; wela=0; while(1) display(keyscan(); void display(uchar aa) dula=1; P0=tableaa-1; dula=0; uchar keyscan() P3=0xfe; temp=P3; temp=temp&0xf0; while(temp!=0xf0) delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) temp=P3; switc

28、h(temp) Case 0xee:num=1; break; case 0xde:num=2; break; case 0xbe:num=3; break; case 0x7e:num=4; break; while(temp!=0xf0) temp=P3; temp=temp&0xf0; P3=0xfd; temp=P3; temp=temp&0xf0; while(temp!=0xf0) delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) temp=P3; switch(temp) case 0xed:num=

29、5; break; case 0xdd:num=6; break; case 0xbd:num=7; break; case 0x7d:num=8; break; while(temp!=0xf0) temp=P3; temp=temp&0xf0; P3=0xfb; temp=P3; temp=temp&0xf0; while(temp!=0xf0) delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) temp=P3; switch(temp) case 0xeb:num=9; break; case 0xdb:nu

30、m=10; break; case 0xbb:num=11; break; case 0x7b:num=12; break; while(temp!=0xf0) temp=P3; temp=temp&0xf0; P3=0xf7; temp=P3; temp=temp&0xf0; while(temp!=0xf0) delay(5); temp=P3; temp=temp&0xf0; while(temp!=0xf0) temp=P3; switch(temp) case 0xe7:num=13; break; case 0xd7:num=14; break; case

31、0xb7:num=15; break; case 0x77:num=16; break; while(temp!=0xf0) temp=P3; temp=temp&0xf0; return num; Lesson6-1 #include<reg52.h> sbit csda=P32; sbit wr=P36; void main() csda=0; wr=0; P0=0; while(1); Lesson6-2 #include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit

32、 wr=P36; sbit rd=P37; void delay(uint z) uint t1,y; for(t1=z;t1>0;t1-) for(y=110;y>0;y-); void init(); void start(); void main() init(); while(1) start(); delay(20); rd=0; delay(10); rd=1; delay(10); void init() P0=0; void start() wr=1; wr=0; wr=1; Lesson7 #include<reg52.h> unsigned char

33、 flag,a; void main() TMOD=0x20;/設置定時器1為工作方式2 TH1=0xfd; TL1=0xfd; TR1=1; REN=1; SM0=0; SM1=1; EA=1; ES=1; while(1) /* if(RI=1) RI=0; P1=SBUF; */ if(flag=1) ES=0; flag=0; SBUF='1'/28; while(!TI); TI=0; SBUF='2'/28; while(!TI); TI=0; SBUF='3'/28; while(!TI); TI=0; ES=1; void ser

34、() interrupt 4 RI=0; / P1=SBUF; a=SBUF; flag=1; Lesson8 #include<reg52.h> #define uchar unsigned char #define uint unsigned int uchar code table="I LIKE MCU!" uchar code table1="WWW.TXMCU.COM" sbit lcden=P34; sbit lcdrs=P35; sbit dula=P26; sbit wela=P27; uchar num; void del

35、ay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); void write_com(uchar com) lcdrs=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; void write_data(uchar date) lcdrs=1; P0=date; delay(5); lcden=1; delay(5); lcden=0; void init() dula=0; wela=0; lcden=0; write_com(0x38); write_com(0x0e); wr

36、ite_com(0x06); write_com(0x01); write_com(0x80+0x10); void main() init(); for(num=0;num<11;num+) write_data(tablenum); delay(20); / write_com(1); write_com(0x80+0x53); for(num=0;num<13;num+) write_data(table1num); delay(20); for(num=0;num<16;num+) write_com(0x18); delay(20); while(1); Lesso

37、n9 #include<reg52.h> #define uchar unsigned char sbit sda=P20; sbit scl=P21; uchar a; void delay() ; void start() /開始信號 sda=1; delay(); scl=1; delay(); sda=0; delay(); void stop() /停止 sda=0; delay(); scl=1; delay(); sda=1; delay(); void respons() /應答 uchar i; scl=1; delay(); while(sda=1)&&

38、amp;(i<250)i+; scl=0; delay(); void init() sda=1; delay(); scl=1; delay(); void write_byte(uchar date) uchar i,temp; temp=date; for(i=0;i<8;i+) temp=temp<<1; scl=0; delay(); sda=CY; delay(); scl=1; delay(); / scl=0; / delay(); scl=0; delay(); sda=1; delay(); uchar read_byte() uchar i,k;

39、scl=0; delay(); sda=1; delay(); for(i=0;i<8;i+) scl=1; delay(); k=(k<<1)|sda; scl=0; delay(); return k; void delay1(uchar x) uchar a,b; for(a=x;a>0;a-) for(b=100;b>0;b-); void write_add(uchar address,uchar date) start(); write_byte(0xa0); respons(); write_byte(address); respons(); wri

40、te_byte(date); respons(); stop(); uchar read_add(uchar address) uchar date; start(); write_byte(0xa0); respons(); write_byte(address); respons(); start(); write_byte(0xa1); respons(); date=read_byte(); stop(); return date; void main() init(); write_add(23,0xaa); delay1(100); P1=read_add(23); while(1

41、); Lesson10 #include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit dula=P26; sbit wela=P27; sbit rs=P35; sbit lcden=P34; sbit s1=P30; sbit s2=P31; sbit s3=P32; sbit rd=P37; uchar count,s1num; char miao,shi,fen; uchar code table=" 2007-7-30 MON" uchar code table1

42、=" 00:00:00" void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); void write_com(uchar com) rs=0; lcden=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; void write_date(uchar date) rs=1; lcden=0; P0=date; delay(5); lcden=1; delay(5); lcden=0; void init() uchar num; dula=0;

43、 wela=0; lcden=0; / fen=59; / miao=53; / shi=23; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); write_com(0x80); for(num=0;num<15;num+) write_date(tablenum); delay(5); write_com(0x80+0x40); for(num=0;num<12;num+) write_date(table1num); delay(5); TMOD=0x01; TH0=(65536-50000

44、)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; void write_sfm(uchar add,uchar date) uchar shi,ge; shi=date/10; ge=date%10; write_com(0x80+0x40+add); write_date(0x30+shi); write_date(0x30+ge); void keyscan() rd=0; if(s1=0) delay(5); if(s1=0) s1num+; while(!s1); if(s1num=1) TR0=0; write_com(0x80+0x

45、40+10); write_com(0x0f); if(s1num=2) write_com(0x80+0x40+7); if(s1num=3) write_com(0x80+0x40+4); if(s1num=4) s1num=0; write_com(0x0c); TR0=1; if(s1num!=0) if(s2=0) delay(5); if(s2=0) while(!s2); if(s1num=1) miao+; if(miao=60) miao=0; write_sfm(10,miao); write_com(0x80+0x40+10); if(s1num=2) fen+; if(

46、fen=60) fen=0; write_sfm(7,fen); write_com(0x80+0x40+7); if(s1num=3) shi+; if(shi=24) shi=0; write_sfm(4,shi); write_com(0x80+0x40+4); if(s3=0) delay(5); if(s3=0) while(!s3); if(s1num=1) /* if(miao=0) miao=59; write_sfm(10,miao); write_com(0x80+0x40+10); */ miao-; if(miao=-1) miao=59; write_sfm(10,m

47、iao); write_com(0x80+0x40+10); if(s1num=2) fen-; if(fen=-1) fen=59; write_sfm(7,fen); write_com(0x80+0x40+7); if(s1num=3) shi-; if(shi=-1) shi=23; write_sfm(4,shi); write_com(0x80+0x40+4); void main() init(); while(1) keyscan(); / while(1); void timer0() interrupt 1 TH0=(65536-50000)/256; TL0=(65536

48、-50000)%256; count+; if(count=18) count=0; miao+; if(miao=60) miao=0; fen+; if(fen=60) fen=0; shi+; if(shi=24) shi=0; write_sfm(4,shi); write_sfm(7,fen); write_sfm(10,miao); Lesson11-shizhong.c #include<reg52.h> #include<define.h> void delay(uint z) uint x,y; for(x=z;x>0;x-) for(y=110;y>0;y-); void didi() beep=0; delay(50); beep=1; delay(100); beep=0; delay(50); beep=1; void write_com(uchar com) rs=0; lcden=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; void write_date(uchar date) rs=1; lcden=0; P0=date

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論