1.3. Experiments turn on the LED and the shift to right

In this experiment an LED that is connected to PORTC will be turned on alternately

# include <mega8535.h>
# include <delay.h>
int temp;
void main(void)
{
DDRC=0xFF;
temp=1<<7; //bit ke-7 diberi logika 1
PORTC=~temp;
delay_ms(100);

while (1)
{
// Place your code here
delay_ms(100);
temp>>=1; //geser ke kanan satu kali
PORTC=~temp;
if(temp==0)
{
temp=1<<7; //bit ke-7 diberi logika 1 kenbali
}
};
}

This entry was posted in Tutorial AVR C Codevision. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>