728x90

728x90

Saturday, April 25, 2020

ATMega32 using a single port for input and output

In the previous example, I show an example of digital input output programming using distinct port.Now I show how to use a single port for for bot input and output. The overall operation of the program just like the previous one. So I just modify the port.

PORTC is used for both input and output

Source is written using Atmel Studio 7:
/*
 * setResetSinglePort.c
 *
 * Created: 4/25/2020 7:27:50 PM
 * Author : admin
 */ 
#include <avr/io.h>
#define setButton (PINC&0b10000000)
#define resetButton (PINC&0b01000000)
int main(void)
{
    DDRC=0b00111111; // PC7 AND PC6 ARE INPUT
    PORTC=0b11000000; //SET PULLUP HIGH FOR PC7 AND PC6
    /* Replace with your application code */
    while (1) 
    {
        if (setButton==0) PORTC=0b11000001;
        if (resetButton==0)  PORTC=0b11000000;
    }
}
Back to main tutorial page ATMega32 tutorials in C with Atmel Studio 7.


No comments:

Post a Comment

320x50

Search This Blog

tyro-728x90