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

why does this code go to sleep

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



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

why does this code go to sleep
PostPosted: Mon Jan 11, 2010 12:50 pm     Reply with quote

this code does not loop....so simple yet pulling my hair out...yikes

thanks

Code:
#include <16F690.h>
#device adc=10
#fuses INTRC_IO, NOWDT, BROWNOUT
#use delay(clock=4000000)

int main() { 


set_tris_a(0b00000000);    // 1 is input  0 is output
set_tris_b(0b10000000);
set_tris_c(0b00010000);

while(1==1)
{

output_high(pin_c0);

}
}


Last edited by brianm on Mon Jan 11, 2010 1:04 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 12:51 pm     Reply with quote

How do you know it goes to "sleep" ? What tests are you doing to
prove this ?
brianm



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

led isnt staying lite
PostPosted: Mon Jan 11, 2010 1:06 pm     Reply with quote

the led on pin c0.....is not staying on...it comes on once then off....and thats it.

shouldnt the while loop keep executing.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 1:10 pm     Reply with quote

How is this being tested ? In hardware or in a simulator ?

Does the LED have a series resistor, to limit the current ?
brianm



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

testing
PostPosted: Mon Jan 11, 2010 4:08 pm     Reply with quote

Testing is being done with hardware...breadboard.

The hardware works as I wrote an assembler program to do the same thing and no problem.

Led connected in series with pin C0 via a 220 ohm resistor.

Ultimately I want to have 2 switch used to increment/decrement a number used as an alarm point.

I do see the led come on once when I first burn the PIC but then I expected the led to stay on for ever.

Brian
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 4:41 pm     Reply with quote

Post your compiler version. It's given at the top of the .LST file, which
will be in your project directory after a successful compilation. It's a
4-digit number in this format: x.xxx
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 5:15 pm     Reply with quote

Try flashing the LED. That will tell you if it is, actually, sleeping.

Code:
while(1)
{

  output_high(pin_c0);
  delay_ms(500);
  output_low(pin_c0);
  delay_ms(500);

}


Or something like that. The LED should flash and not stop.

Ronald
brianm



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

further information
PostPosted: Tue Jan 12, 2010 9:51 am     Reply with quote

Version numbers

CCS PCM C Compiler, Version 4.062, 41368 12-Jan-10 09:40

mplab 8.43

windows vista

programmer pickit2

in mplabsim it seems to work the way it is suppose to...although I am not that versed on the simulator, this has been a good chance to make use of it as it is a simple program to follow....

include the .lst file for reference

-----------------------------------------

Thanks for the flashing idea...but I tried that too....in case I had the wrong logic but still no joy....

Code:
CCS PCM C Compiler, Version 4.062, 41368               12-Jan-10 09:40

               Filename: F:\microchip\projects in c\first c program.lst

               ROM used: 83 words (2%)
                         Largest free fragment is 2048
               RAM used: 7 (3%) at main() level
                         8 (3%) worst case
               Stack:    1 locations

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   019
0003:  NOP
.................... 
.................... #include <16F690.h>
.................... //////// Standard Header file for the PIC16F690 device ////////////////
.................... #device PIC16F690
.................... #list
.................... 
.................... 
.................... #fuses INTRC_IO, NOWDT, BROWNOUT
.................... #use delay(clock=4000000)
0004:  MOVLW  27
0005:  MOVWF  04
0006:  BCF    03.7
0007:  MOVF   00,W
0008:  BTFSC  03.2
0009:  GOTO   018
000A:  MOVLW  01
000B:  MOVWF  21
000C:  CLRF   20
000D:  DECFSZ 20,F
000E:  GOTO   00D
000F:  DECFSZ 21,F
0010:  GOTO   00C
0011:  MOVLW  4A
0012:  MOVWF  20
0013:  DECFSZ 20,F
0014:  GOTO   013
0015:  GOTO   016
0016:  DECFSZ 00,F
0017:  GOTO   00A
0018:  RETLW  00
.................... 
.................... 
.................... int main() {   
0019:  CLRF   04
001A:  BCF    03.7
001B:  MOVLW  1F
001C:  ANDWF  03,F
001D:  MOVLW  61
001E:  BSF    03.5
001F:  MOVWF  0F
0020:  MOVF   0F,W
0021:  BCF    03.5
0022:  BSF    03.6
0023:  BCF    1F.0
0024:  BCF    1F.1
0025:  BCF    1F.2
0026:  BCF    1F.3
0027:  BCF    03.6
0028:  BCF    1F.6
0029:  MOVLW  00
002A:  BSF    03.6
002B:  MOVWF  1E
002C:  CLRF   19
002D:  CLRF   1A
002E:  BSF    03.5
002F:  CLRF   1E
0030:  BCF    03.5
0031:  CLRF   1B
0032:  BCF    03.6
0033:  BCF    0D.5
.................... 
.................... 
.................... set_tris_a(0b00000000);    // 1 is input  0 is output
0034:  MOVLW  00
0035:  BSF    03.5
0036:  MOVWF  05
.................... set_tris_b(0b10000000);
0037:  MOVLW  80
0038:  MOVWF  06
.................... set_tris_c(0b00010000);
0039:  MOVLW  10
003A:  MOVWF  07
.................... 
.................... while(1==1)
.................... {
.................... 
.................... output_high(pin_c0);
003B:  BCF    07.0
003C:  BCF    03.5
003D:  BSF    07.0
.................... delay_ms(1000);
003E:  MOVLW  04
003F:  MOVWF  26
0040:  MOVLW  FA
0041:  MOVWF  27
0042:  CALL   004
0043:  DECFSZ 26,F
0044:  GOTO   040
.................... output_low(pin_c0);
0045:  BSF    03.5
0046:  BCF    07.0
0047:  BCF    03.5
0048:  BCF    07.0
.................... delay_ms(1000);
0049:  MOVLW  04
004A:  MOVWF  26
004B:  MOVLW  FA
004C:  MOVWF  27
004D:  CALL   004
004E:  DECFSZ 26,F
004F:  GOTO   04B
.................... }
0050:  BSF    03.5
0051:  GOTO   03B
.................... }
.................... 
.................... 
.................... 
0052:  SLEEP

Configuration Fuses:
   Word  1: 3FE4   INTRC_IO NOPROTECT BROWNOUT MCLR NOCPD NOWDT PUT IESO FCMEN
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 10:03 am     Reply with quote

RC0 is an analog input at power up. You need to configure it for digital I/O.
It's in the data sheet.
_________________
David
Henry8
Guest







PostPosted: Tue Jan 12, 2010 10:08 am     Reply with quote

Analog / Comparator setup?.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 12, 2010 10:11 am     Reply with quote

WIth your original code what do you get at RC0 when you measure it with a voltmeter?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 12, 2010 11:24 am     Reply with quote

I installed vs. 4.062 and used the program in your first post,
and programmed it into a 16F690 on a 3M breadboard. It worked.
However, initially it didn't work. So I reached over and wiggled
the series resistor and pushed it further into the 3M breadboard,
and then it worked. Solidly.

If it doesn't work for you, check all connections. Also:

1. What is the Vdd voltage on the PIC ?
2. Do you have an MCLR pull-up resistor ?
brianm



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

more inforamtion
PostPosted: Wed Jan 13, 2010 5:00 pm     Reply with quote

ok yes I had a 10k resistor to pin a3 -mclr.....

so i removed it and same thing......so i put a

#fuse nomclr in the program and it worked(s) fine

I still dont understand why it wont work with the mclr held high?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 13, 2010 5:46 pm     Reply with quote

Quote:

I still dont understand why it wont work with the mclr held high?

programmer pickit2

In the PICkit 2 User's Guide, on page 11 (pg. 15 in the Acrobat reader),
http://ww1.microchip.com/downloads/en/DeviceDoc/51553E.pdf
it describes a tickbox option in the Programmer menu for the PicKit 2:
Quote:

Hold Device in Reset -

When checked, the MCLR (VPP) pin is held low (asserted). When
unchecked, the pin is released (tri-stated), allowing an external
pull-up to bring the device out of Reset.

I think it's likely that you have this option selected. It's holding MCLR
in a reset state. If you disable MCLR on the PIC, then it doesn't matter
if that pin is held low.
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