Uploaded by juwel roy

LAB mid Problem

advertisement
Problem: Continuously scroll your first name on any line of an LCD from left to right. Use a push button to
stop/start scrolling. Interface a 16x2 LCD to port D of ATmega32 and a button to one of the pins of PORTA.
Code:
#include <mega32.h>
#include <alcd.h>
#include <delay.h>
void main (void)
{
unsigned char y;
DDRA = 0x00;
PORTA = 0b00000001;
lcd_init(16);
lcd_clear();
lcd_gotoxy(0,0);
while(1)
{
for(y = 0; y<16; y++)
{
if (PINA == 0b00000001)
{
lcd_clear();
lcd_gotoxy(y-1,0);
lcd_puts("Juwel");
delay_ms(100);
lcd_clear();
}
else if(PINA ==0x00)
{
while (PINA==0x00)
{
lcd_gotoxy(y-1,0);
lcd_puts("Juwel");
}
}
}
}
}
Fig01: First name scrolling control
Problem 02: Continuously display the last 4-digits of your UIU ID on a set of four 7-segment displays using
PORTB of ATmega32. Control the common cathode displays using 4 pins of PORTA.
Code:
#include <mega32.h>
#include <delay.h>
void main (void)
{
DDRA = 0x0F;
PORTA = 0x0F;
DDRB = 0xFF;
while(1)
{
PORTA =0b00001110;
PORTB = 0x06;
delay_ms(100);
PORTA =0b00001101;
PORTB =0x3F;
delay_ms(100);
PORTA =0b00001011;
PORTB =0x6F;
delay_ms(100);
PORTA=0b00000111;
PORTB = 0x7D;
delay_ms(100);
}
}
Download