Minggu, 13 April 2014

up down AVR ATmega16


 



#include <mega16.h>
#include <delay.h>
#define UP PIND.4
#define DOWN PIND.5
#define RESET PIND.6
// Declare your global variables here
char a=0;
//b=0;
void main(void)
{
// Declare your local variables here

PORTA=0x00;
DDRA=0x00;

PORTB=0x00;
DDRB=0xFF;

PORTC=0x00;
DDRC=0xFF;


PORTD=0xFF;
DDRD=0x00;   

a=9;
PORTB=a;       
while (1)
      {
      // Place your code here
      if (UP==0){
         if (a<9){
         a++;  
         PORTB=a;
         delay_ms(500);
         }
      }   
     
      if (DOWN==0){     
      a--;   
          if (a==255){
          a=0;
          }
      PORTB=a;
      delay_ms(500);
      }
     
      if (RESET==0){
      a=0;  
      PORTB=a;
      PORTC=a;
      delay_ms(500);
      } 

      }
}

0 komentar:

Posting Komentar