Go Down

Topic: code arduino timer (Read 487 times) previous topic - next topic

shitokung

first time i use mikroC make program for Timer

void main()
{
unsigned char clock[9];

int i,i1,y;

TRISB = 0x00;
TRISC = 0x00;
PORTC = 0x00;
TRISA = 0xFF;
ADCON1 = 0x07;      //inputs are set to digital

Lcd_Init(&PORTB);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);


                   T0CON=0x05;
                   TMR0H=0xC2;
                   TMR0L=0xF7;
                   INTCON.TMR0IF=0; //clear tmr0 overflow bit
                   T0CON.TMR0ON=1;    //Start timer0


     while(1)
{

Lcd_Chr(1,7,clock[7]+48);
Lcd_Chr(1,8,clock[6]+48);
              Lcd_Chr(1,9,clock[5]+48);
              Lcd_Chr(1,10,clock[4]+48);
              Lcd_Chr(1,11,':');
              Lcd_Chr(1,12,clock[3]+48);
              Lcd_Chr(1,13,clock[2]+48);
              Lcd_Chr(1,14,':');
              Lcd_Chr(1,15,clock[1]+48);
              Lcd_Chr(1,16,clock[0]+48);


              while(!INTCON.TMR0IF);
              T0CON.TMR0ON=0;

              clock[0]++;

.....

if(clock[0]>9)

              {

              clock[1]++;
              clock[0] = 0;

              }

              if(clock[1] >5)
                             {
                             clock[2]++;
                             clock[1]=0;
                             }


              if(clock[2]>9)
              {
                        clock[2]=0;
                        clock[3]++;
              }
              if(clock[3]>5)
              {
                        clock[3]=0;
                        clock[4]++;
              }
              if(clock[4]>9)
              {
                        clock[4]=0;
                        clock[5]++;
              }
           if(clock[5]>9)
           {
               clock[5]=0;
               clock[6]++;
           }
           if(clock[6]>9)
           {
               clock[6]=0;
               clock[7]++;
           }

           if(clock[6]==3&&clock[7]>3)    // return to start
              {
                        clock[6]=0;
                        clock[7]=0;
              }

for count

but I don't know how to code  to arduino
such as :  Lcd_Chr(1,9,clock[5]+48);   How to write command to arduino

Could you tell me please Thank you.

Krodal

The Arduino IDE contains examples how to use the LCD library, "File/Examples/LiquidCrystal".

http://arduino.cc/en/Reference/LiquidCrystal
http://arduino.cc/en/Tutorial/LiquidCrystal

If you want to write the code yourself, you could use the digitalWrite() function to toggle the select/enable/data lines.
http://arduino.cc/en/Reference/digitalWrite

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy