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 CCS Technical Support

the time isnt right?

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







the time isnt right?
PostPosted: Mon Feb 19, 2007 10:55 pm     Reply with quote

hi!
today i will be make a seccond time model in my program.
but i calculated follow as .i tested counter timer fast .i check really time.
my model have question.
have body can teach me .where is error ? tHK u

#include <16F877.h>
#use delay(clock=10000000)
#fuses NOWDT,HS,NOLVP,BROWNOUT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include <LCD>

#define CLK_74164 PIN_C3
#define D0_74164 PIN_C1 /
#define CLR_74164 PIN_C2

unsigned int j=0,sec1=0,min1=0;
const char a[]={0x80,0xeb,0x4c,0x49,0x2b,0x19,0x38,0x8b,0x08,0x0b,0xff};




void write_74164(BYTE eo) {
BYTE i;

for(i=1;i<=8;++i) { // Clock out bits from the eo array
if((((eo))&0x80)==0)
output_low(D0_74164);
else
output_high(D0_74164);
shift_left(&eo,1,0);
output_low(CLK_74164);
output_high(CLK_74164);
}
}

#int_timer0
void timer0_isr()
{
set_timer0(100);
j++;
if (j==1000)
{
sec1++;
j=0;
lcd_gotoxy(1,2);printf(lcd_putc,"\nnow sec:=%u",sec1);
if (sec1==60)
{ min1++;
sec1=0;
write_74164(a[min1]);
}
}
}

void init74164(void)
{
output_low(CLR_74164);
DELAY_MS(100);
output_high(CLR_74164);
output_low(CLR_74164); //clock l
output_high(CLR_74164);//clock h
delay_ms(100);
}


void main()
{
unsigned int i;



init74164();
lcd_init();

write_74164(0xf7);
delay_ms(1000);

i=0;
do
{
write_74164(a[i]);
lcd_gotoxy(1,1);printf(lcd_putc,"now number:=%u",i);
delay_ms(300);
i++;
}
while (i<11);
write_74164(a[10]);


setup_counters(rtcc_internal,rtcc_div_16);
enable_interrupts(int_timer0);
enable_interrupts(global);

while(1);
//output_low(CLR_74164);




}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 19, 2007 11:21 pm     Reply with quote

Read posts on Timer0 accuracy:

See Ttelmah's post:
http://www.ccsinfo.com/forum/viewtopic.php?t=18175

See Neutone's post at the end of this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=17915
WHUNG.JOHN
Guest







I FIND LCD DISPLAY DELAY QUESTION!
PostPosted: Tue Feb 20, 2007 11:40 am     Reply with quote

HI:PROGRAMMER SIR
i have read u suggest on post information.
and i find my program have some area that the same question.
i have modified finish.but i calculate timer0 counter still very fast .
and I have checked time still have question.
sir ,please direct error area.
i calcuate method follow as ;
because i use 10MZ clock,so i calcuate is => 1/10MZ/(4*16)=6.4us
i want to get a second. so i calcuate is => 1ms=1000us
1000us/6.4us=156 ticks and check calcuate 156*6.4us=998.4us
the 998.4us is very the same 1ms value number for my use .
i modified my program.please tell me my think where is bad.
my modified in here.follow as

#include <16F877.h>
#use delay(clock=10000000)
#fuses NOWDT,HS,NOLVP,BROWNOUT
#include <LCD>

#define CLK_74164 PIN_C3
#define D0_74164 PIN_C1
#define CLR_74164 PIN_C2

int j=0,sec1=0,min1=0;
const char a[]={0x80,0xeb,0x4c,0x49,0x2b,0x19,0x38,0x8b,0x08,0x0b,0xff};

#int_TIMER0
void TIMER0_isr(void)
{
set_timer0(100);
j++;
if (j==1000)
{
sec1++;
j=0;

}

}

void write_74164(BYTE eo)
{
BYTE i;

for(i=1;i<=8;++i) {
if((((eo))&0x80)==0)
output_low(D0_74164);
else
output_high(D0_74164);
shift_left(&eo,1,0);
output_low(CLK_74164);
output_high(CLK_74164);
}
}
void init74164(void)
{
output_low(CLR_74164);
DELAY_MS(100);
output_high(CLR_74164);
output_low(CLR_74164); //clock l
output_high(CLR_74164);//clock h
delay_ms(100);

}


void main()
{

init74164();
lcd_init();


setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
enable_interrupts(INT_TIMER0);
enable_interrupts(global);
write_74164(0xf7);
while(1)
{

lcd_gotoxy(1,2);printf(lcd_putc,"\fnow sec:=%u",sec1);
delay_ms(100);

if (sec1==60)
{ min1++;
sec1=0;
write_74164(a[min1]);
}
}

}
ckielstra



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

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 11:58 am     Reply with quote

Code:
int j=0
In the CCS compiler an int is 8 bits by default. You try to add it up to 1000, this doesn't fit. Change it to int16.
whung.john
Guest







modified finish pls recheck have any error
PostPosted: Tue Feb 20, 2007 8:48 pm     Reply with quote

ckielstra wrote:
Code:
int j=0
In the CCS compiler an int is 8 bits by default. You try to add it up to 1000, this doesn't fit. Change it to int16.


thk u very much.the counter ready is variant units is int16.
i modified follow as .please help me check my modified what have error

#include <16F877.h>
#use delay(clock=10000000)
#fuses NOWDT,HS,NOLVP,BROWNOUT
#include <LCD>

#define CLK_74164 PIN_C3
#define D0_74164 PIN_C1
#define CLR_74164 PIN_C2

int16 j=0;
int sec1=0,min1=0;

const char a[]={0x80,0xeb,0x4c,0x49,0x2b,0x19,0x38,0x8b,0x08,0x0b,0xff};

#int_TIMER0
void TIMER0_isr(void)
{
set_timer0(100);
if (j++==1000)
{
sec1++;
j=0;

}

}

void write_74164(BYTE eo)
{
BYTE i;

for(i=1;i<=8;++i) { // Clock out bits from the eo array
if((((eo))&0x80)==0)
output_low(D0_74164);
else
output_high(D0_74164);
shift_left(&eo,1,0);
output_low(CLK_74164);
output_high(CLK_74164);
}
}
void init74164(void)
{
output_low(CLR_74164);
DELAY_MS(100);
output_high(CLR_74164);
output_low(CLR_74164); //clock l
output_high(CLR_74164);//clock h
delay_ms(100);

}


void main()
{
//unsigned int i;


init74164();
lcd_init();

setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
enable_interrupts(INT_TIMER0);
enable_interrupts(global);
write_74164(0xf7);
while(1)
{

lcd_gotoxy(1,2);printf(lcd_putc,"\fnow sec:=%4u",sec1);
delay_ms(100);

if (sec1==60)
{ min1++;
sec1=0;
write_74164(a[min1]);
}
}
}
ckielstra



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

View user's profile Send private message

PostPosted: Thu Feb 22, 2007 11:02 am     Reply with quote

Quote:
please help me check my modified what have error
What is the error you have now?
Did the previous change improve things? How fast is the clock counting?
whung.john
Guest







no opinion
PostPosted: Fri Feb 23, 2007 9:53 am     Reply with quote

ckielstra wrote:
Quote:
please help me check my modified what have error
What is the error you have now?
Did the previous change improve things? How fast is the clock counting?


Laughing my affable friend.
i only hope get suggest,and i can improve more complete for apprentice(me).
so i hope get u sound again (suggest for program). and written
"please help me check my modified what have error " describe.
SORRY,NOT OTHER MATTERS.yet thanks u very much .
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