您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > AVR单片机经典教程(含丰富实例程序)下
AVRC91AVRCIARC,*.HEX,C,,!C,AVRC9.1AVR–C•MCU––,–––,–•––AVR?!IARAVR•/••IAR•••32––ALU–•–1KBytes-8MBytes––(SPM)•–16MBytes–CC*var1,*var2;*var1++=*--var2;AVRC92LDR16,-XSTZ+,R16••Auto(localvariables)–1632•––––ZeroSUBR16,R24SUBIR16,1SBCR17,R25SBCIR17,016AVRC93Non-destructivecomparisonCPR16,R24CPCR17,R25CPCR18,R26CPCR19,R27••Zero••Switch•SwitchesCASE•Straightforwardapproach•switch•switch•AVR•AtmelIARAVRC94•AVR—C(Assembly)C:••••Crypticcode••Non-portableC:•••••I/O•I/O:temp=PIND;INR16,LOW(16)•I/O:TCCR0=0x4F;LDIR16,79OUTLOW(51),R16•I/O•0x1FI/O:PORTB|=(1PIND2);SBILOW(24),LOW(2)ADCSR&=~(1ADEN);CBILOW(6),LOW(7)•0x1FI/O:TCCR0&=~(0x80);INR16,LOW(51)ANDIR16,LOW(127)OUTLOW(51),R16I/O•0x1Fwhile(PIND&(1PIND6));SBICLOW(16),LOW(6)RJMP?0002•0x1Fwhile(!(TIFR&(1TOV0)));AVRC95INR16,LOW(56)SBRSR16,LOW(0)RJMP?000416••8:charcount8=5;do{}while(--count8);LDIR16,5DECR16BRNE?0004•Total6bytes•16:intcount16=5;do{}while(--count16);LDIR24,LOW(5)LDIR25,0SBIWR24,LWRD(1)BRNE?0004Total8Bytes•–startup–SRAM–•––•voidmain(void){charlocal;local=local-34;}SUBIR17,LOW(34)•Total2bytes•charglobal;voidmain(void){global=global-45;AVRC96}LDSR16,LWRD(global)SUBIR16,LOW(45)STSLWRD(global),R16Total10Bytes•:typedefstruct{intt_count;charsec;//globalsecondscharmin;//globalminutes}t;ttime;Voidmain(void){t*temp=&time;temp-sec++;temp-min++;temp-t_count++;}•charadd(charnumber1,charnumber2){returnnumber1+number2;}R16-R23•for(;;){}•charcounter=100;do{}while(--counter);Pre-decrement•••••for(;;)•do{}while;CAVR,•AVRC979.2C••C––C––,AVR–/–UART–Toolflow•:AT90S8515•CCompiler——C•AVRStudio——AVR•SL-AVR——AVR•:–PortD()–PortB(LED,)(920.c)#includeio8515.h/*AT90S8515*/voidmain(void){charc;DDRB=0xFF;/*PortBalloutputs*/for(;;)/*Eternalloop*/{c=PIND;/*ReadPortD*/PORTB=c;/*PortB*/}}9.2.1.CIARReadme,,,,921,,,9.2.2CIARAVRC98922923AVRC99Project-OptionsAVRC910AVRC911928929,–ProjectMakeF9,,,,,,929AVRC9129.,*.d90,*.a90,921092109.2.3AVRStudio,C,3.21.AVRStudio,2.(TestProg.d90)-File-Open9211•AT90S8515()•VIEW–I/O(PinB,PortD)–Processor–Watch»c»PORTB»PIND•,TogglePINDbits9211“Debug”9.2.4•(3.30AVR)AVRC9139.3Main•“main”C••:voidmain(void){/**/}•I/O•#includeio8515.h/*8515*/voidmain(void){DDRD=0xFF;/*PortD*/}9.3.1/#includeio8515.h/*AT90S8515*/voidmain(void){charc;DDRB=0xFF;/*PortB*/for(;;)/**/{c=PIND;/*PortD*/PORTB=c;/*PortB*/}}9.3.2#includeio8515.h/*8515*/voiddelay(unsignedintdelayValue){unsignedinti;for(i=0;idelayValue;i++)/**/;/*Donothing*/}9.3.2A:voidmain(void)AVRC914{unsignedcharrunner=0x01;DDRB=0xff;/*PortB*/for(;;)/**/{if(runner)runner=1;elserunner=0x01;PORTB=runner;/*LED*/delay(100);/**/}}9.3.3/E2PROM/*IARI/O/E2PROM*/#includeio8515.h#includeina90.hvoidmain(void){chartemp=0;_EEPUT(0x10,temp);/*E2PROM0x10*/_EEGET(temp,0x10);/*E2PROM0x10*/AVRC915AVRC916AVRC917AVRC918AVRC919AVRC920AVRC921AVRC922AVRC923AVRC924AVRC925AVRC926AVRC927A3331(510630),:020-875788528551019113808842100132616(100086),:010-826235518262355013601177874E-mail:gzsl@sl.com.cn;E-mail:bjslbb@ihw.com.cn;:30,,IAR,,;,,;,,SPI,UART,IIC,LCD,LED(,);,199,ICCAVR,1380,ICE-200(2200),3200/ImageCraftICCAVR1SETUP.EXEabcSETUP.EXEdabdrive:\setup.exedrivecd1302ICCAVRIccAVRC-2-://:vectornumberfunc2:vector...func1func2retiretvectornumber#pragmactaskfunc1func2...RTOSRTOS#pragmatext:name#pragmadata:dataEEPROMEEPROM#pragmaabs_address:addressaddress#pragmaend_abs_addressC++(Project-Options-Compiler)C++//(Project-Options-Compiler)0b1|0*0b1010121asm(string)4IccAVRC-4-:4//4funcICCAVRIARinterrupt[vector_name]func()//vector_nameIARCIARflashFLASHICCAVRconstIARICCAVRICCAVR1IDEProjectOpen\icc\examples.avrledled.cProjectOptionsTargetProjectMakeProjectIDE\icc\examples.avrled.hexINTELHEXAVRMCUCOFFAVRStudioProjectOptionsCOFFIDEled.cProjectMakeProjectIDECProjectNewfoo.prjfoo.hexfoo.cof(C)BuildIDEATMELAVRStudioCOFFATMELAVRStudioIccAVRC-5-*LED*/voidDelay(){unsignedchara,b;for(a=1;a;a++)for(b=1;b;b++);}voidLED_On(inti){PORTB=~BIT(i);/*LED*/Delay();}voidmain()4{inti;DDRB=0xFF;/*B*/PORTB=0xFF;/*BLED*/while(1){/*LED*/for(i=0;i8;i++)LED_On(i);/*LED*/for(i=8;i0;i--)LED_On(i);/*LED*/for(i=0;i8;i+=2)LED_On(i);for(i=7;i0;i-=2)LED_On(i);}}IccAVRC-6-
本文标题:AVR单片机经典教程(含丰富实例程序)下
链接地址:https://www.777doc.com/doc-6242819 .html