21/10/2013
Embedded Systems Design ELEN90066
Lecture 21 LCD and PWM
David Jahshan
Notes from last lectures
• SET and GET revisited
• SPI basics
• How to bit bang SPI
• Using the SPI module/unit to communicate
• Initialising the LCD screen
• Lecture 20 we spoke about how to do exams at Melbourne Uni, slides uploaded
– Correction, no calculators permitted for this exam. • Nothing hard to calculate
ATMEGA notation
• 1<
pages = MAX_PAGES – 1;
Pages must be unsigned for this to work else you need to also check if less than 0!
To select a column
• Two bytes need to be sent to select a column – Most significant 4 bits
– Least significant 4 bits
– Command bit sequence is 0000 EFGH for LSB
– 0001 IJKL for MSB
– So to select column 0x55 (85)
– Send command bits 0000 0101
– Send command bits 0001 0101 LCD_command_tx(0x05); LCD_command_tx(0x15);
Self Documenting
#define CMD_COL_LSB 0x00 #define CMD_COL_MSB 0x10
select_column (byte column) {
byte page_cmd_address_MSB;
byte page_cmd_address_LSB;
page_cmd_address_LSB =(CMD_COL_LSB | (column&0x0F)); page_cmd_address_MSB =(CMD_COL_MSB | (column >> 4)); LCD_command_tx(page_cmd_address_LSB); LCD_command_tx(page_cmd_address_MSB);
return(true);
}
select_column(55);//selects the 55th column select_column(0x33);//selects the 51st column
Write Data
• Once the column and page is selected write data.
• LCD_data_tx(0xFF);
• Writing a byte of 0xFF will turn on 8 pixels
in a column
• If you write 0x01 you will turn on the first pixel
• You can use _BV to turn on specific pixels
2
21/10/2013
Etcha Sketch
• Lets ignore 8 pixels at a time issue for now Pseudo code in main loop: while(infinite_loop)
{
if(up_button) page++; if(down_button) page –; if(left_button)column–; if(right_button)column++; select_page(page); select_column(column); LCD_data_tx(0xFF); _delay_ms(255);
}
So what about all those pixels?
• Youneedaframebuffer
byte frame_buffer[MAX_COLUMNS][MAX_PAGES];
• In this matrix you store the pixels that are active.
• To set the new pixel, use the variable row instead of page
– Replace page++ in up button with row++ and page– with row–
• page=row/8;//findoutwhichpage
• pixel=row%8;//findoutwhichpixel
• _BV(pixel) | frame_buffer[column][page];
while(infinite_loop) {
}
All together
if(up_button) row++; if(down_button) row –; if(left_button)column–; if(right_button)column++; page = row/8;
pixel = row%8;
select_page(page);
select_column(column);
pixel = (_BV(pixel) | (frame_buffer[column][page])); frame_buffer[column][page] = pixel; LCD_data_tx(pixel);
_delay_ms(255);
Pulse Width Modulation
Source: Page 71 ATMEGA16 datasheet
PWM module
• Very flexible module
– Consists of a counter
– Counter driven clock source
– Output compare register
– Waveform Generator
– Configuration is stored in TCCRn
PWM module
• In TCCRn you set the following – Clock source from
• clock, divider, external source – Waveform Generation Mode
• Normal, Phase Correct, Clear on compare match, Fast PWM
– Compare Output Mode
• Disabled, toggle, clear or set on compare match
3
21/10/2013
Source: Page 205 ATMEGA16 datasheet Analogue to Digital Conversion
Assignment Marks
• 1.SchematicLayout20%
• 2.PCBLayout40%
• 3.Qualityofyourcode20%
10% is it self documenting, without magic
numbers, with intelligent use of code space. 2% does it compile
2% without warnings
2% implements etch a sketch
2% with frame buffer 2% with interrupts
Assignment Marks
• 4. Functionality of your Console 20% 2% power supply
1.5v/1.2v in 3.3v out 2% soft power
consistently turns on and off with soft power 2% buttons
buttons can activate something else 2% LEDs
can be activated by the uC 6% LCD
2% Backlight with PWM 2% RAM
2% Battery Low
Bonus Marks
• 6. Bonus applications 10% extra up to full marks on the assignment (you can not get more than full marks)
3% Touch screen etch a sketch with variable resistors
1% with touch screen 3% game 1
3% game 2
Assignment Marking
• Lastdayofsemester,thisFriday.
• Whatyouhaveonthisdayiswhatwillbe marked! No extensions! If you require special consideration your mark can be adjusted after marking,
• Youapplyforspecialconsiderationviathefaculty.
• YoucangetyoursmarkedonThursdayarvoifyou
want, long queues expected on Friday!
• Therewillbethreemarkersatthesessionson Friday.
Assignment Marking
• There will be three queues put your name on the one relevant to you
• Queue 1 Assignment completed with more than 1 bonus (Bonus Queue)
• Queue 2 Etcha Sketch working, does not need to be battery powered (Working Queue)
• Queue 3 Parts of your system are working, or your system is not working (Almost There Queue)
4
21/10/2013
Assignment Marking
• Whenyourturnisapproachingsetupyourcode on a computer (yours is fine), call over the marker, upload your code, demonstrate your product. You have absolute max of 5 minutes, practice what you are going to show before you start.
• Ifyouareinthe‘AlmostThere’queuewireyour system up to the power supply and demonstrate what is working and show some pseudo code.
Next Lecture
• About the exam • Lecture revision
5