a simple question about this program

Discussion in 'Embedded Systems and Microcontrollers' started by roberty, Jan 6, 2011.

  1. roberty

    Thread Starter New Member

    Aug 18, 2010
    11
    0
    hi every one
    this program is belong to a project whit AVR (( atmega16)) and is written to controll a DC motor whit this microcontroller. i had a question about this code (( that is written in C language)) and i want you to do me a favour and answer this question
    here is the program:
    Code ( (Unknown Language)):
    1. #include <mega16.h>
    2.  
    3. // Alphanumeric LCD Module functions
    4. #asm
    5.    .equ __lcd_port=0x1B ;PORTA
    6. #endasm
    7. #include <lcd.h>
    8. #include<delay.h>
    9. void display_no(int no);
    10. void direction(char dir);
    11.  
    12. void main(void)
    13. {
    14.  
    15. // Input/Output Ports initialization
    16. // Port A initialization
    17. PORTA=0x00;
    18. DDRA=0x00;
    19.  
    20. // Port B initialization
    21. PORTB=0x00;
    22. DDRB=0x08;
    23.  
    24. // Port C initialization
    25. PORTC=0x00;
    26. DDRC=0x00;
    27.  
    28. // Port D initialization
    29. PORTD=0x00;
    30. DDRD=0xFF;
    31.  
    32. // Timer/Counter 0 initialization
    33. TCCR0=0x6A;
    34. TCNT0=0x00;
    35. OCR0=0x00;
    36.  
    37. // Timer/Counter 1 initialization
    38. TCCR1A=0x00;
    39. TCCR1B=0x00;
    40. TCNT1H=0x00;
    41. TCNT1L=0x00;
    42. ICR1H=0x00;
    43. ICR1L=0x00;
    44. OCR1AH=0x00;
    45. OCR1AL=0x00;
    46. OCR1BH=0x00;
    47. OCR1BL=0x00;
    48.  
    49. // Timer/Counter 2 initialization
    50. ASSR=0x00;
    51. TCCR2=0x00;
    52. TCNT2=0x00;
    53. OCR2=0x00;
    54.  
    55. // External Interrupt(s) initialization
    56. // INT0: Off
    57. // INT1: Off
    58. // INT2: Off
    59. MCUCR=0x00;
    60. MCUCSR=0x00;
    61.  
    62. // Timer(s)/Counter(s) Interrupt(s) initialization
    63. TIMSK=0x00;
    64.  
    65. // Analog Comparator initialization
    66. // Analog Comparator: Off
    67. // Analog Comparator Input Capture by Timer/Counter 1: Off
    68. ACSR=0x80;
    69. SFIOR=0x00;
    70.  
    71. // LCD module initialization
    72. lcd_init(16);
    73. PORTC=255;
    74. direction(3);
    75. while (1)
    76.       {
    77.  
    78.       if (PINC.2==0 || PINC.3==0 || PINC.4==0 )
    79.       {    
    80.           delay_ms(10);
    81.           if (PINC.2==0)
    82.                   direction(1);
    83.           if (PINC.3==0)
    84.                  direction(2);
    85.           if (PINC.4==0)
    86.                  direction(3);
    87.  
    88.        }
    89.  
    90.       lcd_gotoxy(0,1);
    91.       lcd_putsf("           ");
    92.       lcd_gotoxy(0,1);
    93.       lcd_putsf("OCR0: ");
    94.       display_no(OCR0);
    95.  
    96.       if (PINC.0==0 || PINC.1==0 )
    97.       {    
    98.           delay_ms(10);
    99.  
    100.           if (PINC.0==0)
    101.           {    
    102.  
    103.               if (OCR0> 250)
    104.                   OCR0=255;
    105.               else
    106.                   OCR0=OCR0+5;
    107.           }    
    108.           else if (PINC.1==0)
    109.           {    
    110.  
    111.                    if(OCR0<5)
    112.                       OCR0=0;
    113.                    else      
    114.                       OCR0=OCR0-5;
    115.           }        
    116.        }
    117.        else
    118.        {
    119.  
    120.  
    121.        }    
    122.  
    123.     }
    124. }
    125.  
    126. /////////////////////////
    127. void direction(char dir)
    128. {
    129.    switch(dir)
    130.    {
    131.          case 1:
    132.          PORTD.0=0;
    133.          PORTD.1=1;
    134.          lcd_clear();
    135.          lcd_putsf("Direction: Left ");
    136.          break;
    137.  
    138.          case 2:
    139.          PORTD.0=1;
    140.          PORTD.1=0;
    141.          lcd_clear();
    142.          lcd_putsf("Direction: Right ");
    143.          break;
    144.  
    145.          case 3:
    146.          PORTD.0=0;
    147.          PORTD.1=0;
    148.          lcd_clear();
    149.          lcd_putsf("Direction: Brake ");
    150.          break;
    151.    }
    152. }
    153. /////////////////////////
    154. void display_no(int no)
    155. {  
    156.    int array[5];
    157.    int i=0,j;
    158.    /*if( no < 0)
    159.    {
    160.       lcd_putchar('-');
    161.       no=-1*no;
    162.    }
    163.    else
    164.       lcd_putchar('+');*/
    165.     while(no > 9)
    166.     {
    167.        array[i++]=no % 10;
    168.        no/=10;
    169.     }
    170.     array[i]=no;
    171.     for(j=i;j >=0 ;j--)  
    172.     {
    173.        lcd_putchar(48+array[j]);
    174.        delay_us(100);
    175.        }
    176.  
    177. }
    178. [/i]


    i want to know what are those (( pinc)) variables in LCD defination parts..??

    thanks alot.
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    PINC.1 corresponds to an input on PORTC BIT 1.

    hgmjr
     
    Last edited: Jan 6, 2011
Loading...