caramoan tour package

caramoan tour package

Author Topic: 16f628a countdown Timer using PIC  (Read 331 times)

Offline capcom

  • CR2032 Battery
  • **
  • Posts: 43
  • Pogi/Ganda Points: 0
16f628a countdown Timer using PIC
« on: November 29, 2011, 09:25:36 PM »
Nagbabakasakali lang po baka makatulongan nyo ako sa ginagawa kung countdown timer pagpinush ang button ay magstart na syang magdecreement, hindi ako gaanong shure sa pagkakagamit ko ng interrupt nagstart palang ako magaral nito, sana po matulongan nyo ako, ayaw pa kasing gumana nung code,no errors sya pero hindi nagdedecreement,at di rin natunog yung buzzer, bakit kaya

// LCD module connections
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

sbit COINS at RA2_bit;
sbit Relay_Switch at RA3_bit;

char MSG1[]="Charging Device" ;
char MSG2[]="Not Charging";
char MSG3[]="HH:MM:SS";

unsigned short HHMMSS_Pos[]={3,4,5,6,7,8,9,10};
unsigned short TIME[]={0,0,10,0,0,10,0,0};
unsigned short i;
unsigned short Num,Sec,ChangeSec,Mint,ChangeMin,ChangeHour=0;
unsigned short Hour,Minute,Second;

void Disp_First_Row(){
if (Relay_Switch==0) Lcd_Out(1,1,MSG2);
if (Relay_Switch==1) Lcd_Out(1,1,MSG1);//
}

void Disp_Char(unsigned short col, unsigned short chr){
Lcd_Chr(2,col,chr+48);
}

void Disp_Time(){
 for(i=0;i<8;i++){
 Disp_Char(HHMMSS_Pos,TIME);}
 }

 void Play_Sound(){
 Sound_Play(2500,500);}

void Debounce(){
Delay_ms(500);
}

void Disable_Timer(){
INTCON=0x00;
Relay_Switch=0;
INTCON.T0IF=0;
Disp_First_Row();
Disp_Time();
Play_Sound();
}

void interrupt(){
Num++;
      if(Num==18){
      Sec++;
      ChangeSec=1;
      Num=0;
           if(Sec==60){
           Mint++;
           ChangeMin=1;
           Sec=0;
                 if(ChangeMin=60){
                 ChangeHour=1;
                 Mint=0;
                 }
           }
TMR0=39;
INTCON.T0IF=0;      }
}

void main(){
CMCON=7;
TRISA=0b00100100;
TRISB=0b00000000;
Sound_Init(&PORTA,4);
Relay_Switch=0;
Num=0;
Sec=0;
ChangeMin=0;
ChangeHour=0;
i=0;

Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_Cursor_OFF);
Lcd_Out(1,1,"Charging Station");
Lcd_Out(2,1,"Welcome");

while(i<4){
Debounce();
i++;}

Lcd_Cmd(_LCD_CLEAR);
Disp_First_Row();
Disp_Time();

do{
   if(COINS==0){
   Debounce();
   Play_Sound();
   TIME[3]=2;
   OPTION_REG=0x07;
   TMR0=39;
   INTCON=0xA0;
   INTCON.T0IF=0;
   Disp_Time();
              }
   Hour=Time[0]*10+Time[1];
   Minute=Time[3]*10+Time[4];
   Second=Time[6]*10+Time[7];

   if(COINS==1){
                if(ChangeMin==1){
                                 if(Minute=0&&Hour>0){
                                 Minute=59;
                                 Hour--;  }   //Decrement
                                 }
                                 if(Hour=0&&Minute>0){
                                 Minute--;}
                if(ChangeMin==0)
                                if(ChangeSec=1){
                                                if(Second=0&&Minute>0){
                                                Second=59;
                                                Minute--;}
                                                if(Minute=0&&Second>0){
                                                Second--;}
                                }
                }
}while(1);
}


Philippine Electronics Forum

16f628a countdown Timer using PIC
« on: November 29, 2011, 09:25:36 PM »

Offline capcom

  • CR2032 Battery
  • **
  • Posts: 43
  • Pogi/Ganda Points: 0
Re: 16f628a countdown Timer using PIC
« Reply #1 on: November 30, 2011, 06:55:43 AM »
ang interrupt po ba nagstart after mo ideclare na interrupts ang global interrupts are set to 1?tulad nito sa loob ng do lang sya magbibilang?
void main() {
 ANSEL = 0b00000000;    // All I/O pins are configured as digital
 CMCON0 = 0x07 ;        // Disbale comparators
 TRISC = 0b00010000;    // PORTC all outputs except RC4
 TRISA = 0b00000100;    // PORTA all outputs except RA2
 INTCON = 0b10010000;   // Set GIE and INTE bits
 OPTION_REG.INTEDG = 0; // External interrupt on falling edge of RA2/INT pin
 count = 0;
 LED = 0;
 PORTC = count;
 do {
  count ++;
  if (count ==16) count =0;
  PORTC = count;
  delay_ms(1000);
 }while (1); // infinite loop
}

Philippine Electronics Forum

Re: 16f628a countdown Timer using PIC
« Reply #1 on: November 30, 2011, 06:55:43 AM »

Offline SpongeBob

  • Lead Acid Battery
  • *******
  • Posts: 660
  • Pogi/Ganda Points: 33
Re: 16f628a countdown Timer using PIC
« Reply #2 on: November 30, 2011, 11:41:51 AM »
Yun una mong post timer interrupt, yun pangalawa edge interrupt.
Bago gumana yan kailangan ma-satisfy yun requirement ng interrupt. Dapat set ang GIE at yung particular interrupt enable bit.
Kung timer interrupt dapat may overflow at kung edge dapat may rising or falling edge bago ma-execute yung code sa ISR.

Philippine Electronics Forum

Re: 16f628a countdown Timer using PIC
« Reply #2 on: November 30, 2011, 11:41:51 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com