NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Vertical Scrolling

January 08, 2010
by omer921
omer921's Avatar

I have created a program that scroll text vertically :

// initialload.c // for NerdKits with ATmega168 // mrobbins@mit.edu

define F_CPU 14745600

include <stdio.h>

include <avr/io.h>

include <avr/interrupt.h>

include <avr/pgmspace.h>

include <inttypes.h>

include "../libnerdkits/delay.h"

include "../libnerdkits/lcd.h"

include <avr/io.h>

include <avr/delay.h>

int main() { // LED as output DDRC |= (1<<PC5);

// turn on LED
PORTC |= (1<<PC5);

// fire up the LCD
lcd_init();
lcd_home();

// print message to screen // 20 columns wide: // 01234567890123456789 lcd_line_one(); lcd_write_string(PSTR(" Some times if")); lcd_line_two(); lcd_write_string(PSTR(" you think hard it")); lcd_line_three(); lcd_write_string(PSTR(" might pay off ")); lcd_line_four(); lcd_write_string(PSTR(" ** ")); delay_ms(1000); lcd_line_one(); lcd_write_string(PSTR(" **")); lcd_line_two(); lcd_write_string(PSTR(" Some times if")); lcd_line_three(); lcd_write_string(PSTR(" you think hard it")); lcd_line_four(); lcd_write_string(PSTR(" might pay off ")); delay_ms(1000); lcd_line_one(); lcd_write_string(PSTR(" might pay off ")); lcd_line_two(); lcd_write_string(PSTR(" **")); lcd_line_three(); lcd_write_string(PSTR(" Some times if")); lcd_line_four(); lcd_write_string(PSTR(" you think hard it")); delay_ms(1000); lcd_line_one(); lcd_write_string(PSTR(" you think hard it")); lcd_line_two(); lcd_write_string(PSTR(" might pay off ")); lcd_line_three(); lcd_write_string(PSTR(" ** ")); lcd_line_four(); lcd_write_string(PSTR(" Some times if")); delay_ms(1000); lcd_line_one(); lcd_write_string(PSTR(" Some times if")); lcd_line_two(); lcd_write_string(PSTR(" you think hard it")); lcd_line_three(); lcd_write_string(PSTR(" might pay off ")); lcd_line_four(); lcd_write_string(PSTR(" "));

// busy loop while(100) {

}

return 0; }

April 05, 2010
by Ralphxyz
Ralphxyz's Avatar

This is really cool. I was wondering how to do this, it will take some refinement to fit what I have in mind but you did the hard part, Thanks

Ralph

Here is the corrected code (minor typos and extra }):

#define F_CPU 14745600
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"
#include <avr/io.h>
#include <avr/delay.h>

int main() { // LED as output DDRC |= (1<<PC5);

// turn on LED
PORTC |= (1<<PC5);

// fire up the LCD
lcd_init();
lcd_home();
// print message to screen 
// 20 columns wide: 
// 01234567890123456789 lcd_line_one();

lcd_write_string(PSTR(" Some times if")); 
lcd_line_two(); 
lcd_write_string(PSTR(" you think hard it")); 
lcd_line_three(); 
lcd_write_string(PSTR(" might pay off ")); 
lcd_line_four(); lcd_write_string(PSTR(" * ")); 
delay_ms(1000); 
lcd_line_one(); 
lcd_write_string(PSTR(" *")); 
lcd_line_two(); 
lcd_write_string(PSTR(" Some times if")); 
lcd_line_three(); 
lcd_write_string(PSTR(" you think hard it")); 
lcd_line_four(); 
lcd_write_string(PSTR(" might pay off ")); 
delay_ms(1000); 
lcd_line_one(); 
lcd_write_string(PSTR(" might pay off ")); 
lcd_line_two(); 
lcd_write_string(PSTR(" *")); 
lcd_line_three(); 
lcd_write_string(PSTR(" Some times if")); 
lcd_line_four(); 
lcd_write_string(PSTR(" you think hard it")); 
delay_ms(1000); 
lcd_line_one(); 
lcd_write_string(PSTR(" you think hard it")); 
lcd_line_two(); 
lcd_write_string(PSTR(" might pay off ")); 
lcd_line_three(); 
lcd_write_string(PSTR(" * ")); 
lcd_line_four(); 
lcd_write_string(PSTR(" Some times if")); 
delay_ms(1000); 
lcd_line_one(); 
lcd_write_string(PSTR(" Some times if")); 
lcd_line_two(); 
lcd_write_string(PSTR(" you think hard it")); 
lcd_line_three(); 
lcd_write_string(PSTR(" might pay off ")); 
lcd_line_four(); lcd_write_string(PSTR(" "));

// busy loop while(100) {

return 0; }
April 07, 2010
by Ralphxyz
Ralphxyz's Avatar

The code stops on the last page if you add a while(1) loop it loops around and shows all of the pages again and again.

int main() { // LED as output DDRC |= (1<<PC5);

// turn on LED
PORTC |= (1<<PC5);
while(1)
{
// fire up the LCD
lcd_init();
lcd_home();
...
}

Of course now I have to learn interrupts to get any thing else done.

Anyone know how to do horizontal scrolling?

Ralph

April 08, 2010
by Ralphxyz
Ralphxyz's Avatar

Here is discussion of horizontal scrolling:

And here is the working code for the temperature project:

Ralph

Post a Reply

Please log in to post a reply.

Did you know that a motor is harder to turn when its terminals are shorted together? Learn more...