资源描述:
《pic单片机笔记(pic microcontroller notes)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、pic单片机笔记(PICmicrocontrollernotes)PICmicrocontrollerhasA~Efiveports,ofwhichAhas6bits,Ehas3bits,B,C,D,eachhas8bitports,canbeusedasacommonI/Oport.Witheightchannelanalogchannels1istheinputstate,and0istheoutputstate1//LESONwaterlamp(1)lightaLED#includeVoid,main(){TRISD=0xfe;//settheinputandoutp
2、utdirectionPORTD=0x01;//setlevelWhile(1);}(2)waterlamp#include#defineucharunsignedchar#defineuintunsignedint__CONFIG(0x3B31)Voifdelay(ucharz)//strictlyconsistentinPIC{Uint,x,y;For(x=z;x>0;x--)For(y=110;y>0;y--);}Void,main(){Uchari=8;TRISD=0x00;While(1){PORTD=0x01;For(i=8;i>0;i--){Delay(500
3、);PORTD=PORTD<<1;}}}LESSON2(2)displayofdigitaltube(1)firstdigitaltubesdisplay1(static)#include#defineucharunsignedchar#defineuintunsignedint__CONFIG(0x3B31)Uchar,code,table[]={...};Voifdelay(ucharz)//strictlyconsistentinPIC{Uint,x,y;For(x=z;x>0;x--)For(y=110;y>0;y--);}Void,main(){TRISA=0;T
4、RISD=0;PORTA=0x20;//00100000PORTD=0x06;While(1);}(2)dynamicdisplay;Followedby1,2,3,4,5,6#include#defineucharunsignedchar#defineuintunsignedint__CONFIG(0x3B31)Uchar,code,table[]={...};Voifdelay(ucharz)//strictlyconsistentinPIC{Uint,x,y;For(x=z;x>0;x--)For(y=110;y>0;y--);}Void,main(){TRISA=0
5、;TRISD=0;While(1){PORTA=0x20;PORTD=0x06;Delay(1000);PORTA=0x10;PORTD=0x5b;Delay(1);PORTA=0x08;PORTD=0x4f;Delay(1);PORTA=0x04;PORTD=0x66;Delay(1);PORTA=0x02;PORTD=0x6d;Delay(1);PORTA=0x01;PORTD=0x7d;Delay(1);}}LESSON3keyboard(1)independentkeyboard#include#defineucharunsignedchar#defineuintu
6、nsignedint__CONFIG(0x3B31)Uchar,code,table[]={...};Voifdelay(ucharz)//strictlyconsistentinPIC{Uint,x,y;For(x=z;x>0;x--)For(y=110;y>0;y--);}Void,init(){TRISB=0xff;TRISD=0x00;PORTD=0;}Void,scan(){If(RB0==0){Delay(10);If(RB0==0){While(...RB0);PORTD=0x01;}}If(RB1==0){Delay(10);If(RB1==0){While(...RB1
7、);PORTD=0x02;}}If(RB2==0){Delay(10);If(RB2==0){While(...RB2);PORTD=0x04;}}If(RB0==3){Delay(10);If(RB0==0){While(...RB3);PORTD=0x08;}}}Void,main(){Init();While(1){Scan();}}LESSON5Applicationofrelay#include#define