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

pic 12f675 code

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







pic 12f675 code
PostPosted: Mon Nov 11, 2002 8:53 pm     Reply with quote

Hello to everyone:
I changed this C program to fit the pic-C software. But somehow is not working, can somebody tell me whats wrong.
#include <16C717.h>
#use delay(clock=4000000,RESTART_WDT)
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#ZERO_RAM

setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_DIV_2);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_vref(FALSE);
setup_comparator(FALSE);


int main()
{
const float DIVIDE_NUM = 1.66666;
const float COUNT_SOURCE = 120600;
const float Temp_Conv = 5;

float keepLevel=5;
float evalLevel=0;

float inRealVolts = 0;
float inTEMP = 0;
float countsize = 0;
float counter = COUNT_SOURCE;


while (1)
{
delay_ms(1000);
delay_us(10);
set_adc_channel(0);
inRealVolts = read_adc();
set_adc_channel(1);
delay_us(10);
inTemp = read_adc();

if (inRealVolts >1.66666)
{
inRealVolts = inRealVolts*1.1;
}
inTemp = inTemp / Temp_Conv;
evalLevel = inTEMP - KeepLevel;
if ((evalLevel > 0) && (keepLevel == 5))
{
countsize = (inRealvolts / DIVIDE_NUM);
}
if ((evalLevel > 0) && (keepLevel == 7))
{
countsize = (inRealVolts / DIVIDE_NUM);
keepLevel = 5;
}
if ((evalLevel <= 0) && (keepLevel == 5))
{
countsize = (inRealVolts / DIVIDE_NUM)*2;
keepLevel = 7;
}
if ((evalLevel <= 0) && (keepLevel == 7))
{
countsize = (inRealVolts / DIVIDE_NUM)*2;
}
counter = counter - countsize;
if ((counter>=118188) && (counter <=120600))
{
output_high(PIN_A2);
output_high(PIN_A4);
output_high(PIN_A5);
output_high(PIN_A6);
output_high(PIN_A7);
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
output_high(PIN_B4);

}
if ((counter>=108540) && (counter <118188))
{
output_high(PIN_A2);
output_high(PIN_A4);
output_high(PIN_A5);
output_high(PIN_A6);
output_high(PIN_A7);
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
}
if ((counter>=96480) && (counter <108540))
{
output_low(PIN_A2);
output_low(PIN_A4);
output_low(PIN_A5);
output_low(PIN_A6);
output_low(PIN_A7);
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
}
}
return;
}

I have Vdd connected to 5 V and Vss to ground.
Please if anybody has an idea please email me. It's urgent
email: paiz7820@uidaho.edu
___________________________
This message was ported from CCS's old forum
Original Post ID: 8770
john cutler



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

Re: pic 12f675 code
PostPosted: Mon Nov 11, 2002 10:04 pm     Reply with quote

2 things - first you're using the wrong Device Header File! you have "#include <16C717.h> " it must be
#include<12F675.h>

Also, the names you're using for setup_adc_ports()
RA0, RA1, RA3 are not correct for 12F675

look at the include file for the 12F675.

Good luck!

John


:=Hello to everyone:
:=I changed this C program to fit the pic-C software. But somehow is not working, can somebody tell me whats wrong.
:= #include <16C717.h>
:= #use delay(clock=4000000,RESTART_WDT)
:= #include <float.h>
:= #include <stdio.h>
:= #include <stdlib.h>
:= #ZERO_RAM
:=
:= setup_adc_ports(RA0_RA1_RA3_ANALOG);
:= setup_adc(ADC_CLOCK_DIV_2);
:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:= setup_timer_1(T1_DISABLED);
:= setup_timer_2(T2_DISABLED,0,1);
:= setup_vref(FALSE);
:= setup_comparator(FALSE);
:=
:=
:=int main()
:={
:= const float DIVIDE_NUM = 1.66666;
:= const float COUNT_SOURCE = 120600;
:= const float Temp_Conv = 5;
:=
:= float keepLevel=5;
:= float evalLevel=0;
:=
:= float inRealVolts = 0;
:= float inTEMP = 0;
:= float countsize = 0;
:= float counter = COUNT_SOURCE;
:=
:=
:= while (1)
:= {
:= delay_ms(1000);
:= delay_us(10);
:= set_adc_channel(0);
:= inRealVolts = read_adc();
:= set_adc_channel(1);
:= delay_us(10);
:= inTemp = read_adc();
:=
:= if (inRealVolts >1.66666)
:= {
:= inRealVolts = inRealVolts*1.1;
:= }
:= inTemp = inTemp / Temp_Conv;
:= evalLevel = inTEMP - KeepLevel;
:= if ((evalLevel > 0) && (keepLevel == 5))
:= {
:= countsize = (inRealvolts / DIVIDE_NUM);
:= }
:= if ((evalLevel > 0) && (keepLevel == 7))
:= {
:= countsize = (inRealVolts / DIVIDE_NUM);
:= keepLevel = 5;
:= }
:= if ((evalLevel <= 0) && (keepLevel == 5))
:= {
:= countsize = (inRealVolts / DIVIDE_NUM)*2;
:= keepLevel = 7;
:= }
:= if ((evalLevel <= 0) && (keepLevel == 7))
:= {
:= countsize = (inRealVolts / DIVIDE_NUM)*2;
:= }
:= counter = counter - countsize;
:= if ((counter>=118188) && (counter <=120600))
:= {
:= output_high(PIN_A2);
:= output_high(PIN_A4);
:= output_high(PIN_A5);
:= output_high(PIN_A6);
:= output_high(PIN_A7);
:= output_high(PIN_B0);
:= output_high(PIN_B1);
:= output_high(PIN_B2);
:= output_high(PIN_B3);
:= output_high(PIN_B4);
:=
:= }
:= if ((counter>=108540) && (counter <118188))
:= {
:= output_high(PIN_A2);
:= output_high(PIN_A4);
:= output_high(PIN_A5);
:= output_high(PIN_A6);
:= output_high(PIN_A7);
:= output_low(PIN_B0);
:= output_low(PIN_B1);
:= output_low(PIN_B2);
:= output_low(PIN_B3);
:= output_low(PIN_B4);
:= }
:= if ((counter>=96480) && (counter <108540))
:= {
:= output_low(PIN_A2);
:= output_low(PIN_A4);
:= output_low(PIN_A5);
:= output_low(PIN_A6);
:= output_low(PIN_A7);
:= output_low(PIN_B0);
:= output_low(PIN_B1);
:= output_low(PIN_B2);
:= output_low(PIN_B3);
:= output_low(PIN_B4);
:= }
:= }
:= return;
:=}
:=
:=I have Vdd connected to 5 V and Vss to ground.
:=Please if anybody has an idea please email me. It's urgent
:=email: paiz7820@uidaho.edu
___________________________
This message was ported from CCS's old forum
Original Post ID: 8773
johnpcunningham
Guest







Re: pic 12f675 code
PostPosted: Tue Nov 12, 2002 10:27 am     Reply with quote

<font face="Courier New" size=-1>John Cutler already answered the obvious problems. Here are some additional ideas for you:

ADC
You need to make sure the ADC channel is off for digital inputs and outputs. It defaults to "ALL ANALOG" on reset and should be configured properly in your code.

TYPECAST
When you read a port, you need to typecast the value if you are working with different data types. For example:

inRealVolts = read_adc();

should be:

inRealVolts = float (read_adc());

since you are using the ADC value to compare to a float. Seems odd, but I have learned to typecast everything in my math calculations, if they are of different data types.

PORT MAPPING
You can also write directly to ports by using the define statement to define the port location:

#define PORTA 0x05
#define TRISA 0x85

...in you dcode you can do

TRISA = 0xF8; //set lower 3 bits as outputs
PORTA = 0x07; //set all lower bits on
delay_ms(100);
PORTA = 0x00; //set all lower bits off

for individual bit settings, you could use and/or or
just use the output_high() and output_low settings.

Instead of the PIN_A1 kind of names, try remanimg them so that
your code is easier for you to read:

#define RED_LED PIN_A0
#define BLUE_LED PIN_A1

...in you code, for example:

output_high(RED_LED);
output_low(BLUE_LED);
delay_ms(100);
output_high(BLUE_LED);
output_low(RED_LED);

</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 8802
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