Author Topic: please check my source code for errors  (Read 642 times)

0 Members and 1 Guest are viewing this topic.

Offline vasuTopic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
please check my source code for errors
« on: October 19, 2010, 04:30:06 AM »
Hi all,
This is my first post, i am a begineer when it comes to software and have written this code.
Please let me know if i have made any mistake.



 // Algorithm for Attiny-861 Based Cable testing jig
// date:- 05-10-2010

//################################################################################################

  // Chip Type:- Atmega Attiny-861V
  // Clock frequency:- 8Mhz, internal

//#################################################################################################/



// Pending Set internal clock



  #include <avr/io.h>



 int set_portA_bit( int position,int value);
 int set_portB_bit( int position,int value);
 

  int main()


  {
     
   
// Set Port A and POrt B pin 9 and 10  as output port
 
       DDRA=0XFF;
       DDRB |= (1<<DDB7);
       DDRB |= (1<<DDB6);


// Set PORTA and PORTB pin 9&10 as default high

     PORTA=0XFF;
     PORTB |=(1 << PORTB7);
     PORTB |=(1 << PORTB6);


while(1)

{
 
   set_portB_bit(7,0);

    delay_ms(1000);
   set_portB_bit(7,1);
   set_portB_bit(8,0);


   delay_ms(1000);
   set_portB_bit(8,1);
   set_portA_bit(8,0);

   delay_ms(1000);
   set_portA_bit(8,1);
   set_portA_bit(7,0);

   delay_ms(1000);
   set_portA_bit(7,1);
   set_portA_bit(6,0);

   delay_ms(1000);
   set_portA_bit(6,1);
   set_portA_bit(5,0);

   delay_ms(1000);
   set_portA_bit(5,1);
   set_portA_bit(4,0);

   delay_ms(1000);
   set_portA_bit(4,1);
   set_portA_bit(3,0);

   delay_ms(1000);
   set_portA_bit(3,1);
   set_portA_bit (2,0);


   delay_ms(1000);
   set_portA_bit(2,1);
   set_portA_bit (1,0);


   delay_ms(1000);
   set_portA_bit(1,1);

}

return 1;

}


int set_portA_bit( int position, int value)

{

// sets or clears the bit in position "position"
// either high or low( 1,0) to match "value"
// other bits are unchanged



if (value == 0)

{
PortA &= ~(1<<position);   // set low
}

else
portA |= (1<<position);  // set high


return 1;

}



int set_portB_bit( int position, int value)

{

// sets or clears the bit in position "position"
// either high or low( 1,0) to match "value"
// other bits are unchanged



if (value == 0)

{
PortB &= ~(1<<position);   // set low
}

else
portB |= (1<<position);  // set high


return 1;

}



void delay_ms(unsigned short ms)
 {
   unsigned short outer1, outer2;
   outer1 = 200;
   while (outer1)
   {
      outer2 = 1000;
      while (outer2)
       {
         while ( ms ) ms--;
         outer2--;
       }
      outer1--;
   }
 }



thanks
vasu

 


Get Your Ad Here

data_list