Author Topic: Programming Help!  (Read 3925 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterRykoTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Programming Help!
« on: June 29, 2007, 09:36:49 AM »
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?

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: Programming Help!
« Reply #1 on: June 29, 2007, 10:46:27 AM »
Quote
I'm trying to program the ATMEGA8.  Pins 27 and 28 are already declared as inputs right?
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?
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
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.
« Last Edit: June 29, 2007, 11:00:55 AM by rgcustodio »
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline MasterRykoTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Re: Programming Help!
« Reply #2 on: July 09, 2007, 08:45:27 AM »
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;
}


Offline megaman935

  • Robot Overlord
  • ****
  • Posts: 182
  • Helpful? 0
Re: Programming Help!
« Reply #3 on: July 09, 2007, 08:47:31 AM »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Programming Help!
« Reply #4 on: July 10, 2007, 04:58:10 AM »

 


Get Your Ad Here