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

12F683 Hangs up?

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



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

12F683 Hangs up?
PostPosted: Fri Oct 05, 2007 9:07 am     Reply with quote

Can anyone see what i am doing incorrectly on this program? When i program the chip, it does nothing. The first thing it should do is turn an output pin on then off. It does not doe this. It is almost like the program never starts. I think i am missing something in the set up. And yes, i have confirmed that my circuit is working by loading a different program into the chip.
Compiler version 4.058 PCWHD

#include <12F683.h>
#device adc=10
#use delay(clock=2000000, RESTART_WDT)
#fuses WDT,INTRC_IO, PUT, MCLR, NOBROWNOUT, NOCPD, NOPROTECT
#include <math.h>

#use fast_io(A)
#define GPIO1 PIN_A0
#define LED2 PIN_A1
#define LED3 PIN_A2
#define time_in PIN_A3
#define trn PIN_A4
#define lbo PIN_A5
#define INTS_PER_SECOND 25
////////////////////////////////////////////////////////////////////////////////


char int_count,loop;
long time1,time2,time3,seconds,voltage,hour,day,minute;

////////////////////////////////////////////////////////////////////////////////
#int_rtcc
void clock_isr(void)
{
if(--int_count==0) //decrement counter until 0
{
++seconds; //count up seconds
int_count=INTS_PER_SECOND; //reset counter
if (seconds>=65000)
seconds=65000;
}
}
////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
void main()
{


setup_oscillator(osc_2mhz);
setup_adc_ports(sAN2);
setup_adc(ADC_CLOCK_DIV_8);
setup_wdt(WDT_ON | WDT_DIV_16);
//setup_wdt(WDT_72MS | WDT_ON);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
set_rtcc(0);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
//setup_timer_1(T1_DISABLED);

set_tris_a(0b00011111);
output_high(trn); //shut off solenoid
int_count=INTS_PER_SECOND; //used for timer
seconds=0; //clear out variable
hour=0; //clear low volage counter for seconds
day=0; //clear out day counter
minute=0;
time1=0; //counter for time
loop=TRUE;
delay_ms(1000);
output_low(trn); //shut off solenoid

while (TRUE)
{
output_high(trn); //turn off solenoid
delay_ms(1000);
set_adc_channel(2); //
//output_low(trn); //turn on solenoid
delay_ms(1000);
voltage=read_adc();
while(loop)
{
if((voltage<=1024) && (voltage>=1010))
{
time1=0;
}
if((voltage<=1009) && (voltage>=512))
{
time2=1024-voltage;
time1=time2/8;
}
if((voltage<=511) && (voltage>=0))
{
time3=1024-voltage;
time2=time3-512;
time1=time2*60;
}
if(day>=2)
time1=0;
if(seconds>time1)
{
output_high(trn);
delay_ms(1000);
output_low(trn);
seconds=0;
loop=false;
}
else
output_low(trn);
delay_ms(1000);
seconds=seconds+1;
minute=minute+1;
if(minute>=3600)
{
hour=hour+1;
minute=0;
}
if(hour>=24)
{
day=day+1;
hour=0;
}
}
output_low(trn);
while(TRUE)
{
delay_ms(100);
}
}
}
Ttelmah
Guest







PostPosted: Fri Oct 05, 2007 9:28 am     Reply with quote

Er. MCLR....
You have the MCLR pin defined as 'time_in'. What is connected to this?.

Best Wishes
nmeyer



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

PostPosted: Fri Oct 05, 2007 9:58 am     Reply with quote

It is pulled to Vdd through a 10K. Nothing else.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 05, 2007 10:36 am     Reply with quote

Quote:

When i program the chip, it does nothing. The first thing it should
do is turn an output pin on then off

I assume you're referring to the 'trn' pin ?

Quote:

#define trn PIN_A4

set_tris_a(0b00011111);
output_high(trn); //shut off solenoid

Look closely at your TRIS statement.
nmeyer



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

PostPosted: Fri Oct 05, 2007 10:43 am     Reply with quote

Yes, I just caught and fixed that. It works now.
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