Software > Software

Programming Help!

(1/1)

MasterRyko:
I'm trying to program the ATMEGA8.  Pins 27 and 28 are already declared as inputs right?  I was wondering how i can put that in my code where is pin27 will go high, then pin 3 will go high and pin 4 will go low.  How would i code it show the chip will register that pins 27 and 28 are high?

rgcustodio:

--- Quote ---I'm trying to program the ATMEGA8.  Pins 27 and 28 are already declared as inputs right?
--- End quote ---

Do you want these pins to be inputs or outputs??


Pin27 => PC4 (user selectable)/SDA (input and output)/ADC4 (input only)
Pin28 => PC5 (user selectable)/SCL (output only)/ADC5 (input only)

Primarily, these two pins are used for I2C/TWI (Two Wire Interface). Before you can use them as ports you must disable them as TWI pins. In your program, write a ZERO to the TWEN bit of the TWCR (TWI Control Register). After doing this you can now start controlling the outputs of these two ports.


--- Quote ---I was wondering how i can put that in my code where is pin27 will go high, then pin 3 will go high and pin 4 will go low.  How would i code it show the chip will register that pins 27 and 28 are high?
--- End quote ---

This got me confused. You lost me.

This discussion might be able to help you:

--- Quote ---http://www.societyofrobots.com/robotforum/index.php?topic=1404.0
--- End quote ---

It discusses how to control the ports so that a LED will light up when the port is high. The code you will use will be similar.

MasterRyko:
My goal is to do this...

      Have pins 27 and 28 as inputs, connected to photoresistors, and have pins 2,3,4 as outputs.  When Pin 27 goes high and pin 28 is low, I would like Pin 2 to go high, pin 3 to go low, and pin 4 to go high.  When Pin 28 goes high and pin 27 is low, I would like pin 2 to go low, pin 3 to go high, and pin 4 to go high.  When Pin 27 and 28 are both high i would like pin 2 to go low, pin 3 to go low and pin 4 to go high.  When pin 27 and 28 are both low i want pin 2 to go low, pin 3 to go low and pin 4 to go low.  This is the code i have so far...

#include <avr/io.h>


void beep (unsigned char cycles)
   {

   DDRD |=1<<PD0;
   DDRD |=1<<PD1;
   DDRD |=1<<PD2;
   
   return;
}

int main(void)
{

int sensor_left=0;
int sensor_right=0;



while(1)
{

sensor_left=a2dConert8bit(5);
sensor_right=a2dConvert8bit(4);

if(sensor_left > sensor_right)
         {
         
         PORTD |=1<<PD0;
         PORTD &=!(1<<PD1);
         PORTD |=1<<PD2;
         
         }

      else if(sensor_right > sensor_left)
         {
         
         PORTD &=!(1<<PD0);
         PORTD |=1<<PD1;
         PORTD |=1<<PD2;
         
         }

      else
         {
         
         PORTD &=!(1<<PD0);
         PORTD &=!(1<<PD1);
         PORTD |=1<<PD2;
         
         }
   }
return 0;
}

megaman935:
may be of assistance....
http://www.atmel.com/dyn/resources/prod_documents/2486S.pdf

Admin:
Have you seen my ATmega8 source code yet?
http://www.societyofrobots.com/downloads/sbs_source_photovore_v1.zip

Navigation

[0] Message Index

Go to full version