View previous topic :: View next topic |
Author |
Message |
mateeb4u@gmail.com
Joined: 07 Feb 2012 Posts: 19 Location: pakistan
|
IS there problem in ccs compiler 4.084 |
Posted: Fri Feb 17, 2012 6:00 am |
|
|
I'm working on I2c protocol, at Proteus it works well but practically with pressing the PIN_D0 or PIN_D1, program goes to in it and continuously printing, Tuned Frequency=%f pll=xxxx
Tthe master side coding is
Code: |
#include<18F452.h>
#use delay(clock = 4000000)
#use I2C(MASTER,SLOW, SDA=PIN_C4, SCL=PIN_C3,FORCE_HW,FAST=400000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#fuses NOWDT,NOPROTECT,NOLVP,XT
//BYTE address=0x60;
float tuned_frequency=87.61;
void tuning(float tuned_frequency)
{
long pll;
BYTE frequencyH,frequencyL;
pll=(4*(tuned_frequency*1000+225))/32.768;
printf("pll=%ld",pll);
frequencyL=pll;
frequencyH=pll>>8;
i2c_start();
i2c_write(0xC0);
i2c_write(frequencyH);
printf(" data1=%X ",frequencyH);
i2c_write(FrequencyL);
printf(" data2=%X ",frequencyL);
i2c_write(0x0);
i2c_write(0x10);
i2c_write(0x0);
i2c_stop();
}
void main (void)
{
output_d(0x0);
while(1)
{
int1 up,down;
up=input(PIN_D0);
if(up==1)
{
tuned_frequency=tuned_frequency+.20;
printf(" Tuned Frequency=%f ",tuned_frequency);
output_d(0x0);
tuning(tuned_frequency);
}
down=input(PIN_D1);
if(down==1)
{
tuned_frequency=tuned_frequency-.20;
printf(" Tuned Frequency=%f ",tuned_frequency);
output_d(0x0);
tuning(tuned_frequency);
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
First thought |
Posted: Tue Feb 21, 2012 2:40 am |
|
|
(1) You were using PROTEUS and CCS.
(2) You're now using REAL HARDWARE and CCS.
What changed?
Why should CCS now be faulty when it was OK before?
Why waste time with Proteus?
Why not use REAL hardware from the outset?
Mike |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Second thought |
Posted: Tue Feb 21, 2012 2:42 am |
|
|
How are your switches wired? (Including any resistors. A simple text schematic will do.)
Ignoring what Proteus tells you. What happens when you:-
(1) Press and hold the switch connected to D0?
(2) Release the switch on D0?
(3) Press and hold the switch on D1?
(4) Release the switch on D1?
etc.
I don't have proteus, (correct that, refuse to use Proteus) so can't help there.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Feb 21, 2012 8:06 am |
|
|
int1 up,down;
Declaring variables within a loop is technically not allowed in C and generally a poor idea. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
|