Download presentation
Presentation is loading. Please wait.
Published byGriffin Brown Modified over 9 years ago
1
© AJH 2013, V2.0 Computer Programming Embedded Systems Programming Stand-alone code, system initialisation, operating systems. Low-level operations; port access, bitwise manipulation. Hexadecimal, Binary, two’s complement representation and arithmetic. Computer Programming1
2
© AJH 2013, V2.0 What is … ? … an Embedded System? An electronic system that contains an integral processor, programmed to perform a dedicated task … Real Time Software? Correct operation depends not only on logical correctness of computation but also time at which result is produced … a microcontroller? A complete processor on a single IC, containing CPU, RAM, ROM and Input/Output Computer Programming2
3
© AJH 2013, V2.0TIC-PIC Application Trainer3
4
© AJH 2013, V2.0TIC-PIC Application Trainer4 TIC-PIC Block Diagram B5 B4 B3 B2 B1 B0 C4 C3 C5 C1 C0 C2 A4 A5 +5V Reset PIC18F4520 11.0592 MHz Osc2 Osc1 MAX 232A C7/Rx C6/Tx 2 3 5 RS-232 A3 A2 A1 A0 x8 D7 D0 dp g +5V CC AN7 Temp +5V AN6 LDR +5V AN5 Pot
5
© AJH 2013, V2.0TIC-PIC Application Trainer5 PIC Port Connections RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0 PORTC
6
© AJH 2013, V2.0TIC-PIC Application Trainer6 “Hello World” Write a C program that prints “Hello World” on the screen #include // header defining printf( ) etc int main(void) // main returns successful code to OS { printf(“Hello World\n”); return 0; // return “success” to OS }
7
© AJH 2013, V2.0TIC-PIC Application Trainer7 Embedded “Hello World” #include // Processor specific header #pragma config OSC=HS,PWRT=ON,WDT=OFF,LVP=OFF,PBADEN=OFF,DEBUG=ON void main(void) // note void parameter/return { TRISC=0b10000000; // program port as output while(1){ // infinite loop PORTC=0b00010101; // alternate LEDs on PORTC=0b00101010; // swap over (only 6 LSB available) } // note non-standard binary notation }
8
© AJH 2013, V2.0TIC-PIC Application Trainer8 #include defines port and other identifiers related to the PIC architecture (e.g. PORTC) library not usually relevant to embedded applications
9
© AJH 2013, V2.0TIC-PIC Application Trainer9 #pragma config... Initialises processor configuration fuses –OSC=HShigh speed crystal oscillator –PWRT=ONpower up timer on –WDT=OFFwatchdog timer off –LVP=OFFlow voltage programming off –PBADEN=OFFport B analog enable off –DEBUG=ONdebugging enabled (PICkit2)
10
© AJH 2013, V2.0TIC-PIC Application Trainer10 void main(void) In an embedded application there is no Operating System to which a value can be returned. As a result main( ) returns void.
11
© AJH 2013, V2.0TIC-PIC Application Trainer11 while(1) Embedded program ‘has no end’ While(1)produces an infinite loop which repeats the statements between { and } indefinitely. Alternative is while(TRUE) or for(;;)
12
© AJH 2013, V2.0TIC-PIC Application Trainer12 PORTC = 0b00010101; Ports are ‘memory mapped’ Ports are treated like variables PORTC = 0b00010101; // output data x = PORTB; // input data PORTC = x; // output variable
13
© AJH 2013, V2.0TIC-PIC Application Trainer13 TRISC = 0b10000000; DDRC = 0b10000000; Ports are programmable and must be configured before use. TRIS registers control tristate output buffers (also called DDR) A 1 in TRIS programs port bit as Input A 0 in TRIS programs port bit as Output Non ANSI-standard binary constants
14
© AJH 2013, V2.0TIC-PIC Application Trainer14 I/O Port Block Diagram - Output
15
© AJH 2013, V2.0TIC-PIC Application Trainer15 I/O Port Block Diagram - Input
16
© AJH 2013, V2.0TIC-PIC Application Trainer16 Configuring ports Write down the statements to configure: –Port A, 6 LSB = inputs TRISA = 0b00111111; –Port B, 6 LSB = outputs TRISB = 0; or TRISB = 0b00000000; –Port C, 4 LSB = outputs, 4 MSB = inputs TRISC = 0b11110000;
17
© AJH 2013, V2.0TIC-PIC Application Trainer17 Time Delays A delay is produced by ‘doing nothing’ a large number of times, using an empty for loop void delay(void) { unsigned int d; for(d=10000;d>0;d--); // empty loop } // creates a delay
18
© AJH 2013, V2.0TIC-PIC Application Trainer18 Final Program including Delay #include // Processor specific header #pragma config OSC=HS,PWRT=ON,WDT=OFF,LVP=OFF,PBADEN=OFF,DEBUG=ON void delay(void); // function prototype void main(void) // note void parameter { TRISC=0b10000000; // program port as output for(;;) // infinite loop { PORTC=0b00010101; // alternate LEDs on delay(); PORTC=0b00101010; // swap over (only 6 LSB available) delay(); } // note non-standard binary notation } void delay(void) { unsigned int d; for(d=10000;d>0;d--); // empty loop creates a delay }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.