Trick to set I/O States automatically

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A simple trick to help simulating in the AVR Studio:

If you have a hardware with some pullups on the ports, and annoyed to click them to the right state on every reset, use the follwing code in the start of main:

 main() 
{
    PORTA = 0xFF;
    PORTB = 0xFF; 
    PORTC = 0xFF;
    PORTD = 0xFF;
    PORTE = 0xFF;
    PORTF = 0xFF;
    PORTG = 0xFF; 
   
    DDRA = 0xFF; 
    DDRB = 0xFF;
    DDRC = 0xFF;
    DDRD = 0xFF;
    DDRE = 0xFF;
    DDRF = 0xFF;
    DDRG = 0xFF;

(...)

Then initialize your ports, first initializing DDRx and then PORTx
All Ports which are input, will be pulled hght
(of course, to get them pulled down, set the PORTx-Bit to zero in the code above)