70 likes | 188 Views
Lecture 5B: Simple I/O Embedded C using PIC microcontrollers Teaching resources on on www.eej.ulst.ac.uk My office 5B18, telephone 028 90 366364 My email IJ.McCrum@ulster.ac.uk. EEE305 Microcontroller Systems. Switches.
E N D
Lecture 5B: Simple I/O Embedded C using PIC microcontrollers Teaching resources on onwww.eej.ulst.ac.uk My office 5B18, telephone 028 90 366364 My email IJ.McCrum@ulster.ac.uk EEE305 Microcontroller Systems http://www.eej.ulst.ac.uk/~ian/modules/EEE305
Switches • You can wire a switch up to an input pin, and put the other end of the switch to ground. You need a pullup pin from the port pin to Vdd then to bias the pin high when the switch is not closed. The pullup can be external or internal (PORTB only). • You can also wire a switch up between an input pin and Vdd, in which case you need a pulldown resistor between ground and the pin. • How do you read 16 switches? • Either by wiring them up to a shift register and using 2 or 3 pins to clock the data in serially (see 74HC165 as a suitable chip) or use a multiplexing approach to save pins. Cheap but more complex software
7 Segment displays • To drive a seven segment display needs 7 output lines, or 8 to display decimal point • To drive 4 displays could use 28 or 32 pins. • Common to either use a hardware shift register or a seven segment display controller chip (allows brightness control and flashing) • Or to multiplex pins, 7 to drive the segments and 4 to select which digit is active. • The human eye has persistence of vision so if a display is “on” for 10 out of every 40 msecs it thinks it is on all the time – albeit at 25% brightness. In practice you can exceed the LED continous current limit by a factor of 4 and restore the brightness levels.
Diagram of multiplexed 7-seg 4 digit display Every 10 milliseconds output a pattern from {0001,0010,0100 and 1000}
Resources of the millenium board • PORTA, analog input ch0-2 & LCD (3) • PORTB, 2 bits set aside for programmer • 6 spare use 4 for digit select/keypad row o/p(RB0-3) • PORTC, 2 bits set aside for serial comms to PC • 6 spare, bring in 4 columns from keypad (RC0-3) • PORTD all 8 spare – drive 7 segments a-g, dp • PORTE 3 spare – use for LCD • Leaves RC4,RC5,RB4,RB5 and maybe RA1,2 free