C compilers for 8051 Chin-Shiuh Shih. Assembly Language Machine Dependent Executable Machine Code Symbolic version of machine code Machine dependent Direct,

Download C compilers for 8051 Chin-Shiuh Shih. Assembly Language Machine Dependent Executable Machine Code Symbolic version of machine code Machine dependent Direct,

Post on 22-Dec-2015

216 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

<ul><li> Slide 1 </li> <li> C compilers for 8051 Chin-Shiuh Shih </li> <li> Slide 2 </li> <li> Assembly Language Machine Dependent Executable Machine Code Symbolic version of machine code Machine dependent Direct, low-level hardware control one instruction to one machine code Assembler High-level Language Machine independent (portable) High productivity Compiler one statement to many machine codes </li> <li> Slide 3 </li> <li> Editor XXX.c Source Program Compiler XXX.obj Object Program Linker Library XXX.exe Executable C:\XXX Debugger Development Cycle </li> <li> Slide 4 </li> <li> C compilers for 8051 SDCC - Small Device C Compiler Raisonance RIDE-51 Keil Some issues in using 8051 C compilers Access to SFR (Special Function Register) Implement Interrupt Service Subroutine Memory allocation in variable declaration </li> <li> Slide 5 </li> <li> SDCC - Small Device C Compiler SDCC - Small Device C Compiler is a free C compiler for 8051, although library is incomplete. http://sdcc.sourceforge.net Download sdcc-2.8.0-setup.exe and install. </li> <li> Slide 6 </li> <li> Issue "sdcc test.c" within DOS box will generate "test.ihx" in Intel-HEX format. Issue "sdcc --code-loc 0x4000 --xram-loc 0x8000 test.c" within DOS box will generate "test.ihx" in Intel-HEX format. Option "--code-loc 0x4000" is used to specify starting code address. Option "--xram-loc 0x8000" is used to specify the starting address of external data memory. </li> <li> Slide 7 </li> <li> Refer to "c:\sdcc\share\doc\sdcc\sdccman.pdf" for SDCC Compiler User Guide. uart.c is a UART library by Chin-Shiuh Shieh, including Character, String, and Integer I/O. Refer to sample.c for its usage. </li> <li> Slide 8 </li> <li> // Template for SDCC 8051 C Language #include // Definitions of registers, SFRs and Bits // ISR Prototypes =================================================== void INT0_ISR(void) __interrupt 0; // ISR for External Interrupt 0 void T0_ISR(void) __interrupt 1; // ISR for Timer0/Counter0 Overflow void INT1_ISR(void) __interrupt 2; // ISR for External Interrupt 1 void T1_ISR(void) __interrupt 3; // ISR for Timer1/Counter1 Overflow void UART_ISR(void) __interrupt 4; // ISR for UART Interrupt void main(void) { } void INT0_ISR(void) __interrupt 0 {} void T0_ISR(void) __interrupt 1 {} void INT1_ISR(void) __interrupt 2 {} void T1_ISR(void) __interrupt 3 {} void UART_ISR(void) __interrupt 4 {} </li> <li> Slide 9 </li> <li> Input P1=0xFF; MOV P1,#0FFh A=P1; MOV A,P1 Output P2=0xF5; MOV P2,#0F5h </li> <li> Slide 10 </li> <li> Check button in assembly CHECK_BUTTON: JBP3.2,CBRET ;Task for button pressed WAIT_BUTTON_RELEASE: JNB P3.2,WAIT_BUTTON_RELEASE CBRET: Check button in C if(P3_2==0) { while(P3_2==0); } </li> <li> Slide 11 </li> <li> Wait button in assembly WAIT_BUTTON: JBP3.2,WAIT_BUTTON WAIT_RELEASE: JNBP3.2,WAIT_RELEASE Wait button in C while(P3_2==1); while(P3_2==0); </li> <li> Slide 12 </li> <li> Left Rotation 10010011 00100111 Left Rotation in assembly RL A Left Rotation in C unsigned char i; if(i&gt;=128) i=i*2+1; else i=i*2; </li> <li> Slide 13 </li> <li> Right Rotation 10010011 11001001 Right Rotation in assembly RR A Right Rotation in C unsigned char i; if(i%2==1) i=i/2+128; else i=i/2; </li> <li> Slide 14 </li> <li> data unsigned char test_data; xdata unsigned char test_data; xdata at 0x7ffe unsigned int chksum; idata unsigned char test_data; code unsigned char test_code; bit test_bit; </li> <li> Slide 15 </li> <li> xdata at 0x0000 unsigned char ADC; ADC=0; X=ADC; </li> <li> Slide 16 </li> <li> Slide 17 </li> <li> xdata at 0x3000 unsigned char x[1024]; for(i=0;i</li></ul>

Recommended

View more >