CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

program is not working

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mafia666
Guest







program is not working
PostPosted: Thu Feb 07, 2008 3:19 pm     Reply with quote

When this code is running, after few countings program loses time calculation, restarts the calculation from the beginning. Maybe you will see a problem? Do i need to write results to eeprom? Sorry for dumb question - i am really beginner in programing pic uc.
Code:
#include<16f628.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay (clock=20000000)

#include"lcd628.c"

//**************** Variables*********************************

int trukme,periodas,sekund,minut,daliklis,a,b,busena,menlaik;

#define voztuvas pin_a2
#define variklis pin_a3
#define tarp pin_a0
#define veikim pin_a1


//**************************Time calculation******************
void laikas()
{
daliklis=daliklis+1;
if (daliklis==10)
{
  daliklis=0;
  sekund=sekund+1;
  if (sekund==60)
    {sekund=0; minut=minut+1;}
}
}
//****************************** Budejimas *************************************
void logo()
{
  lcd_gotoxy(1,1);
  printf(lcd_putc,"  Pramoniniai  ");
  lcd_gotoxy(1,2);
  printf(lcd_putc,"  Irenginiai    ");
}
//***************************monitoring***********************
void monitoringas()
{
if (busena==0)
{
  lcd_gotoxy(1,1);
  printf(lcd_putc," Iki Atidarymo  ");
  lcd_gotoxy(1,2);
  printf(lcd_putc," Liko    - min  ");
  lcd_gotoxy(7,2);
  printf(lcd_putc,"\%02d",a);
}
if (busena==1)
{
lcd_gotoxy(1,1);
  printf(lcd_putc," Iki Uzdarymo  ");
  lcd_gotoxy(1,2);
  printf(lcd_putc," Liko    - sek  ");
  lcd_gotoxy(7,2);
  printf(lcd_putc,"\%02d",b);
}
}
//********************* MENIU ***************************
void meniu()
{
lcd_gotoxy(1,1);
  printf(lcd_putc,"Period. -  min ");
  lcd_gotoxy(1,2);
  printf(lcd_putc,"Trukme  -  sek ");
menlaik=0;
ratukas:
menlaik=menlaik+1;
if(!input(tarp)){menlaik=0; periodas=periodas+1; if(periodas==15){periodas=1;} }
if(!input(veikim)){menlaik=0; trukme=trukme+5; if(trukme==55){trukme=5;}}
  lcd_gotoxy(10,1);
  printf(lcd_putc,"\%02d",periodas);
  lcd_gotoxy(10,2);
  printf(lcd_putc,"\%02d",trukme);
delay_ms(200);
if(menlaik<10) goto ratukas;
}
//************************ process*************************
void vykdymas()
{
  if(!input(variklis))
{
laikas();
if(periodas==minut) {sekund=0;minut=0;busena=1;output_high(voztuvas);}
if(busena==1 && trukme==sekund){sekund=0;busena=0;output_low(voztuvas);}
a=periodas-minut;b=trukme-sekund;
monitoringas();
}
  else
  {
logo();
minut=0;sekund=0;
  }
}
//*********************** main program***********************

void main()
{
  lcd_init();
  output_low(pin_b2);
  trukme=25; periodas=5;sekund=0;minut=0;daliklis=0;busena=0;
  delay_ms(300);
  meni:
    if(!input(tarp) || !input(veikim)) meniu();
    vykdymas();
    delay_ms(100);
  goto meni;
}
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Feb 07, 2008 3:45 pm     Reply with quote

Quote:
#use delay (clock=20000000)



XT fuses is for slower osc. (<10 mhz) use HS instead!


Code:
  meni:
    if(!input(tarp) || !input(veikim)) meniu();
    vykdymas();
    delay_ms(100);
  goto meni;



uh you mean While ?


Code:
  While(1){
    if(!input(tarp) || !input(veikim)) meniu();
    vykdymas();
    delay_ms(100);
}

Best Regards,

Laurent
mafia666
Guest







PostPosted: Fri Feb 08, 2008 2:20 am     Reply with quote

The thing is, that lcd shows only menu text, it stops to count time, sometimes seems like pic is being restarted. Can it be because of that fuse? Maybe i need to store data in eeprom or etc?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 08, 2008 8:40 am     Reply with quote

Quote:
sometimes seems like pic is being restarted. Can it be because of that fuse?
Yes, this is possible. A PIC running at 20MHz needs HS fuse. For 4MHz or slower you use XT.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group