caramoan tour package

caramoan tour package

Author Topic: tutor from xperts pls... countdown timer..  (Read 1161 times)

Offline -Al-

  • CR2032 Battery
  • **
  • Posts: 39
  • Pogi/Ganda Points: 0
  • Gender: Male
  • nomanisanisland
tutor from xperts pls... countdown timer..
« on: January 13, 2010, 06:16:44 PM »


pa help naman po sa countdown timer...noob pa po kasi..  >:(

ganyan po sa image balak kong gawin...pwedeng i-set from 1-99 mins..game timer po cya actualy. It should have pause button.ung mga timer po kasing nahahanap ko walang pause, tulad nung "darkroom timer"... and then, i forgot to include, ung isa pong available port mag output po sana ng 1sec pulse. Hahaluan ko nlng po sana ng 24sec ba logic IC's nlng para sumabay dun sa time.

Pa guide naman po sa project ko.... im practising High tech and micro c compilers...request po sanan wag masyadong shortcut mga code mga master.  :D di ko alam umpisahan ung code..tsaka di ko alam i-multiplex ung 4 7-segment....thanks po



Philippine Electronics Forum

tutor from xperts pls... countdown timer..
« on: January 13, 2010, 06:16:44 PM »

Offline Kaizer03

  • Nuclear Reactor
  • ****
  • Posts: 4847
  • Pogi/Ganda Points: 225
  • C#<-->Android<-->Java
    • PhilRobotics
Re: tutor from xperts pls... countdown timer..
« Reply #1 on: January 13, 2010, 10:51:11 PM »
i am in the process of coding.. pero parang di ata tama...hehe ^^

it is better na ikaw mismo gumawa with our guide=)

since C naman ito...mas madali ito comparing sa ASM kung kaya ng ibang beginner malamang kaya mo rin ito=)

ito ang technique sa pagdisplay...

you will have a variable or two which holds the data for the 4 displays..
yun yung magdedecrement..
before mo sya idisplay.. extract the data for the disp1, disp2, disp3 and disp4
after extracting it..

on the pin for the disp4
send the data for it then delay for atleast 20ms..
turn it off then switch on the disp3..
do the same routine up to the disp1

=)

antok na talaga ko hahah di ko lam kung tama ba naitype ko..

basta kaya nyo yan..

ang daming examples nyan dito at sa net..

look at the project boards dito sa elab..meron dun..=)
Lend a hand for those who are in need!=)

Stop Hijacking!=) More Technical Posts!=)
 ;)

Kaizer Killer EX Pre-Alpha

Philippine Electronics Forum

Re: tutor from xperts pls... countdown timer..
« Reply #1 on: January 13, 2010, 10:51:11 PM »

Offline -Al-

  • CR2032 Battery
  • **
  • Posts: 39
  • Pogi/Ganda Points: 0
  • Gender: Male
  • nomanisanisland
Re: tutor from xperts pls... countdown timer..
« Reply #2 on: January 15, 2010, 07:53:50 PM »
eto palng codes ko po...di ko alam kung tama at kung ano ang susunod..binase ko lng dun sa tutorial ni sir paranz...

#include<pic.h>
#include "delay.c"


__CONFIG(XT & PWRTDIS & WDTDIS & UNPROTECT);


unsigned char display_value=0x00;
unsigned char thousands_digit;
unsigned char hundreds_digit;
unsigned char tens_digit;
unsigned char ones_digit;

void display(void)
{
   PORTA=0x01;     
   PORTB=ones_digit;       
   DelayMs(100);   
   
   PORTA=0x02;     
   PORTB=tens_digit;   
   DelayMs(100);           
   
   PORTA=0x04;       
   PORTB=hundreds_digit;       
   DelayMs(100);   

   PORTA=0x08;      
   PORTB=thousands_digit;      
   DelayMs(100);
}
void update_value(unsigned char display_value)
{
   thousands_digit = display_value/1000;       
   hundreds_digit = (display_value - (thousands_digit * 1000))/100;       
   tens_digit = (display_value  -(thousands_digit * 100)- (hundreds_digit * 100))/10;       
   ones_digit = display_value - (hundreds_digit * 100) - (tens_digit * 10);
}

void main()
{
.....
}


hehe..di ko alam codes na gagamitin eh... T_T

Philippine Electronics Forum

Re: tutor from xperts pls... countdown timer..
« Reply #2 on: January 15, 2010, 07:53:50 PM »

Offline -Al-

  • CR2032 Battery
  • **
  • Posts: 39
  • Pogi/Ganda Points: 0
  • Gender: Male
  • nomanisanisland
Re: tutor from xperts pls... countdown timer..
« Reply #3 on: January 26, 2010, 09:00:59 PM »
eto po code ko para sa coundown timer  :)
#include<pic.h>
#include "delay.c"


__CONFIG(XT & PWRTDIS & WDTDIS & UNPROTECT);

   unsigned char count_1sec=0x00;
   unsigned char minutes;
   unsigned char seconds;

void TIMER(void)
{
         count_1sec++;
   
         if (count_1sec>=6)
         {   
            count_1sec=0;
            seconds--;
            if (seconds >= 59)
            {
               seconds=59;
               minutes--;
               if(minutes>99)
               {
                  minutes=0;
               }
            }
         }
               
}
void data_value(void)
{
   unsigned char dat0;
   unsigned char dat1;
   unsigned char dat2;
   unsigned char dat3;

      dat0=minutes%10;
      dat1=minutes/10;
      dat2=seconds%10;
      dat3=seconds/10;

      PORTA=0x01;     
      PORTB=dat2;       
      DelayMs(10);   
   
      PORTA=0x02;     
      PORTB=dat3;   
      DelayMs(10);           
   
      PORTA=0x04;       
      PORTB=dat0;       
      DelayMs(10);   

      PORTA=0x08;      
      PORTB=dat1;      
      DelayMs(10);

}
void main ()   
{   
   
   TRISA  &= 0xF0;     
   TRISB  &= 0xF0;     
   PORTB  &= 0xF0;     
   PORTA  &= 0xF0;   
      
   while(RB4==1)
   {
      data_value();

      if(RB5==0)
      {
         minutes++;
       }
      
   }
   while(1)
   {
      data_value();
      TIMER();
   }
   
   
}

pa help naman po...ano pong code ilalagay ko para sa pause ng timer? tsaka pano ko po gagawing mas acurate ung timer?
nid lang po talaga..

Philippine Electronics Forum

Re: tutor from xperts pls... countdown timer..
« Reply #3 on: January 26, 2010, 09:00:59 PM »

Offline Kaizer03

  • Nuclear Reactor
  • ****
  • Posts: 4847
  • Pogi/Ganda Points: 225
  • C#<-->Android<-->Java
    • PhilRobotics
Re: tutor from xperts pls... countdown timer..
« Reply #4 on: January 27, 2010, 01:33:42 AM »
^

use Timer Interrupt replace your TIMER FUNCTION

to pause it just disable the interrupt then On it again after some command=)


study about Free Run Timer0 then learn on how to compute it..

let say you set your Free Run timer will go to the ISR every 50ms.. then inside your ISR there should be a counter of 200 (50ms*20 = 1s) then if that counter reach 200, it will set it back to 0 then the seconds variable will increment..=) to follow na yung sa minutes
Lend a hand for those who are in need!=)

Stop Hijacking!=) More Technical Posts!=)
 ;)

Kaizer Killer EX Pre-Alpha

Philippine Electronics Forum

Re: tutor from xperts pls... countdown timer..
« Reply #4 on: January 27, 2010, 01:33:42 AM »

Offline -Al-

  • CR2032 Battery
  • **
  • Posts: 39
  • Pogi/Ganda Points: 0
  • Gender: Male
  • nomanisanisland
Re: tutor from xperts pls... countdown timer..
« Reply #5 on: January 27, 2010, 08:19:50 PM »
hehe..sige po...pag aaralan ko..  :D
pede po ba TMR0 kahit F84A?  ???

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: tutor from xperts pls... countdown timer..
« Reply #6 on: January 27, 2010, 08:40:56 PM »
hehe..sige po...pag aaralan ko..  :D
pede po ba TMR0 kahit F84A?  ???


that is about right.  ;)
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline -Al-

  • CR2032 Battery
  • **
  • Posts: 39
  • Pogi/Ganda Points: 0
  • Gender: Male
  • nomanisanisland
Re: tutor from xperts pls... countdown timer..
« Reply #7 on: January 31, 2010, 06:44:53 PM »
void main()
{
   TRISA &= ~0x03;
   PORTA &= ~0x03;
   TRISB &= ~0x1F;
   PORTB &= ~0x1F;
      

   init_TMR0();
   
   while(RB7==1)      //when RB7 button is pressed, start countdown
   {
   display()
   }

   while(1)
   {
      display();
      if(RB6==0)     //pause
      {
      T0IE=0;        //disable TMR0
      }

      if(RB7==0);    //resume
      {
      T0IE=1;     //enable TMR0
      }
      
      if(skip_timer ==0x00)
      {
         sec_24--;
         Skip_timer=999;
         
         if(sec_24 >= 24)
         {
            sec_24=0;
            RB4=1;
            DelayMs(250);
         
         }
         if(sec_24 <= 3)
         {
            RB4=1;
            DelayMs(100);
         }
      }
   }
}


hehe...
2 nights palang ako sa TMR0...
advise naman po...how can i make this code above look nicer  ??? ???...parang di appropriate eh...ehe..
pati po ung pag disable sa TMR0..  >:(
24 sec shot clock...  :D
thanks po...lalo na kay gigz..pogi points nga sayo..ehe

Offline akhen

  • Diesel Generator
  • *
  • Posts: 1293
  • Pogi/Ganda Points: 47
  • Gender: Female
  • "Learning is good but application is 100x better!"
Re: tutor from xperts pls... countdown timer..
« Reply #8 on: January 31, 2010, 07:51:25 PM »
^good job... kaya mo yah sis... mas masarap pa ikaw mismo gumawa...

Offline -Al-

  • CR2032 Battery
  • **
  • Posts: 39
  • Pogi/Ganda Points: 0
  • Gender: Male
  • nomanisanisland
Re: tutor from xperts pls... countdown timer..
« Reply #9 on: February 10, 2010, 09:27:17 AM »
#include <pic.h>
#include "delay.c"

volatile unsigned char skiptimer1=0x00;
unsigned char sec_24=24;
unsigned char sec = 0x00;
unsigned char min = 0x00;
unsigned char secUP = 0x00;
unsigned char minUP = 0x00;
unsigned char start = 0x00;
unsigned char display = 0x00;
unsigned char display_24sec = 0x00;
unsigned char mSec = 0x00;
unsigned char mSecUP = 0x00;


void interrupt ISR(void)
{
      TMR0=56;
      if(skiptimer1)
      skiptimer1--;
      T0IF = 0;

}
void init_TMR0(void)
{
   GIE=0;
   T0CS = 0;          
   PSA = 0;       
   PS2 = 0;       
   PS1 = 0;
   PS0 = 0;
   TMR0 = 56;
   T0IF = 0;
   T0IE=1;
   GIE = 1;    
}

void display_sc(void)
{
   unsigned char ones_sec_24;
   unsigned char tens_sec_24;

   ones_sec_24=sec_24%10;
   tens_sec_24=sec_24/10;

   PORTB=0x01;
   PORTA=ones_sec_24;
   DelayMs(1);

   PORTB=0x02;
   PORTA=tens_sec_24;
   DelayMs(1);
}

void display_countdown(void)
{

   unsigned char ones_sec;
   unsigned char tens_sec;
   unsigned char ones_min;
   unsigned char tens_min;

   ones_sec = sec%10;
   tens_sec = sec/10;
   ones_min = min%10;
   tens_min = min/10;

   PORTB=0x04;
   PORTA=ones_sec;
   DelayMs(1);

   PORTB=0x08;
   PORTA=tens_sec;
   DelayMs(1);

   PORTB=0x20;
   PORTA=ones_min;
   DelayMs(1);

   PORTB=0x40;
   PORTA=tens_min;
   DelayMs(1);

   PORTB=0x80;
   PORTA=mSec;
   DelayMs(1);
}

void display_countup(void)
{
   unsigned char ones_secUP;
   unsigned char tens_secUP;
   unsigned char ones_minUP;
   unsigned char tens_minUP;

   ones_secUP = secUP%10;
   tens_secUP = secUP/10;
   ones_minUP = minUP%10;
   tens_minUP = minUP/10;
   

   PORTB=0x04;
   PORTA=ones_secUP;
   DelayMs(1);

   PORTB=0x08;
   PORTA=tens_secUP;
   DelayMs(1);

   PORTB=0x20;
   PORTA=ones_minUP;
   DelayMs(1);

   PORTB=0x40;
   PORTA=tens_minUP;
   DelayMs(1);

   PORTB=0x80;
   PORTA=mSecUP;
   DelayMs(1);
}

waaaa...pa help po ulit... T_T..something is wrong..ginawa ko po kasing up/down counter and then may hundred mili-sec pa every 100mSec mag increment ang milisec..mya mali po ba sa computation ko?skiptimer value ko po 250.. and .4mSec po ung overflow ng TMR0 ko po...di po kasi cya mag accurate..parati pong behind ng 3 sec in 1 min sa simulation.. T_T..

Philippine Electronics Forum

Re: tutor from xperts pls... countdown timer..
« Reply #9 on: February 10, 2010, 09:27:17 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com