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

PIC16F676 problem
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PIC16F676 problem
PostPosted: Thu Jan 20, 2005 4:02 am     Reply with quote

Hi, PCM 3.214

I have trouble with config bit in the PIC16F676.
This is my code:
#include <16F676.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, NOMCLR, NOCPD, PUT

//#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT


main () {
setup_adc_ports(sAN2|sAN4|sAN5|sAN6|sAN7|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_16);

setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
port_a_pullups(FALSE);



SET_TRIS_a(12);
SET_TRIS_c(15);


do {


output_high(PIN_C4);
delay_ms(10);
output_low(PIN_C4);
delay_ms(10);

} while(1 ) ;




}

This simple code not function, PIN_C4 is always LOW.
I use Internal OSC.
MCLR is wired to Vcc by 1k resistor.
CLKOUT is ok, 1Mhz. I think that the osc function.
I tested my circuit by Compiler Basic and all function.
Can you help me, please!?
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Thu Jan 20, 2005 4:16 am     Reply with quote

Hi again,
This is my last code with assembly:

//Test.h
#include <16F676.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT
/////////////////////////////////////////////////////////////////////////////////

#include "C:\firmware\Test.h"

void main()
{

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

do {

output_high(PIN_C4);
delay_ms(10);
output_low(PIN_C4);
delay_ms(10);

} while(1 ) ;




}

MCLR is wired to Vcc by 1k resistor.
CLKOUT is ok, 1Mhz. I think that the osc function.
I tested my circuit by Compiler Basic and all function.
Can you help me, please!?

OUTPUT:

--- C:\firmware\Test.c ----------------------------
1: #include "C:\firmware\Test.h"
000000 3000 MOVLW 0
000001 08A MOVWF PCLATH
000002 2804 GOTO 0x4
000003 000 NOP
000004 23FF CALL 0x3ff
000005 1683 BSF STATUS, 0x5
000006 090 MOVWF T1CON
000007 3000 MOVLW 0
000008 08A MOVWF PCLATH
000009 281F GOTO @cinit

--- C:\firmware\Test.h ----------------------------

1: #include <16F676.h>
2: #device adc=8
3: #use delay(clock=4000000)
00000A 3023 MOVLW 0x23
00000B 084 MOVWF FSR
00000C 800 MOVF INDF, 0
00000D 1903 BTFSC STATUS, 0x2
00000E 281E GOTO 0x1e
00000F 3001 MOVLW 0x1
000010 0A1 MOVWF 0x21
000011 1A0 CLRF 0x20
000012 BA0 DECFSZ 0x20, 0x1
000013 2812 GOTO 0x12
000014 BA1 DECFSZ 0x21, 0x1
000015 2811 GOTO 0x11
000016 304A MOVLW 0x4a
000017 0A0 MOVWF 0x20
000018 BA0 DECFSZ 0x20, 0x1
000019 2818 GOTO 0x18
00001A 000 NOP
00001B 000 NOP
00001C B80 DECFSZ INDF, 0x1
00001D 280F GOTO 0xf
00001E 3400 RETLW 0

--- C:\firmwareTest.c ----------------------------

1: #include "C:\firmware\Test.h"
2:
3:
4: void main()
5: {
00001F 184 CLRF FSR
000020 301F MOVLW 0x1f
000021 583 ANDWF STATUS, 0x1
000022 131F BCF ADCON0, 0x6
000023 3000 MOVLW 0
000024 3807 IORLW 0x7
000025 1683 BSF STATUS, 0x5
000026 091 MOVWF 0x11
000027 3007 MOVLW 0x7
000028 1283 BCF STATUS, 0x5
000029 099 MOVWF CMCON
00002A 1683 BSF STATUS, 0x5
00002B 805 MOVF PORTA, 0
00002C 1283 BCF STATUS, 0x5
00002D 819 MOVF CMCON, 0
00002E 118C BCF PIR1, 0x3
6:
7: setup_adc_ports(NO_ANALOGS|VSS_VDD);
00002F 131F BCF ADCON0, 0x6
000030 3000 MOVLW 0
000031 1683 BSF STATUS, 0x5
000032 091 MOVWF 0x11
8: setup_adc(ADC_OFF);
000033 1283 BCF STATUS, 0x5
000034 101F BCF ADCON0, 0
9: setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
000035 1683 BSF STATUS, 0x5
000036 801 MOVF TMR0, 0
000037 39C0 ANDLW 0xc0
000038 3808 IORLW 0x8
000039 081 MOVWF TMR0
10: setup_timer_1(T1_DISABLED);
00003A 1283 BCF STATUS, 0x5
00003B 190 CLRF T1CON
11: setup_comparator(NC_NC_NC_NC);
00003C 3007 MOVLW 0x7
00003D 099 MOVWF CMCON
00003E 1683 BSF STATUS, 0x5
00003F 805 MOVF PORTA, 0
000040 3003 MOVLW 0x3
000041 1283 BCF STATUS, 0x5
000042 0A0 MOVWF 0x20
000043 BA0 DECFSZ 0x20, 0x1
000044 2843 GOTO 0x43
000045 819 MOVF CMCON, 0
000046 118C BCF PIR1, 0x3
12: setup_vref(FALSE);
000047 1683 BSF STATUS, 0x5
000048 199 CLRF CMCON
13:
14: do {
15:
16: output_high(PIN_C4);
000049 1207 BCF PORTC, 0x4
00004A 1283 BCF STATUS, 0x5
00004B 1607 BSF PORTC, 0x4
17: delay_ms(10);
00004C 300A MOVLW 0xa
00004D 0A3 MOVWF 0x23
00004E 200A CALL @delay_ms1
18: output_low(PIN_C4);
00004F 1683 BSF STATUS, 0x5
000050 1207 BCF PORTC, 0x4
000051 1283 BCF STATUS, 0x5
000052 1207 BCF PORTC, 0x4
19: delay_ms(10);
000053 300A MOVLW 0xa
000054 0A3 MOVWF 0x23
000055 200A CALL @delay_ms1

Can you help ?Thank
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jan 20, 2005 12:45 pm     Reply with quote

Quote:

#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT


#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT, NOLVP

Try with
Code:

#include <16F676.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT, NOLVP

void main()
{
 do
   {
     output_high(PIN_C4); 
     delay_ms(100);
     output_low(PIN_C4);
     delay_ms(100);
   } while(1 ) ;
}





Humberto Very Happy
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Jan 20, 2005 1:02 pm     Reply with quote

Humberto wrote:
Quote:

#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT


#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT, NOLVP

Try with
Code:

#include <16F676.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, BROWNOUT, MCLR, NOCPD, PUT, NOLVP

void main()
{
 do
   {
     output_high(PIN_C4); 
     delay_ms(100);
     output_low(PIN_C4);
     delay_ms(100);
   } while(1 ) ;
}





Humberto Very Happy


There is no LVP mode for the 16F676
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Thu Jan 20, 2005 1:14 pm     Reply with quote

yes LVP mode not exist
I wrote same code by PIC Basic pro and I haven't problems!!!!.
The circuit is ok, compiler CCS no!
Can you help me please??
Can you send me your code for test only?
Thanks
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Jan 20, 2005 1:20 pm     Reply with quote

Code runs just fine in the simulator.
Ttelmah
Guest







PostPosted: Thu Jan 20, 2005 4:18 pm     Reply with quote

The assembler being generated is 'right'. Looking at this:
Code:

16: output_high(PIN_C4);
000049 1207 BCF PORTC, 0x4
00004A 1283 BCF STATUS, 0x5
00004B 1607 BSF PORTC, 0x4
17: delay_ms(10);
00004C 300A MOVLW 0xa
00004D 0A3 MOVWF 0x23
00004E 200A CALL @delay_ms1
18: output_low(PIN_C4);
00004F 1683 BSF STATUS, 0x5
000050 1207 BCF PORTC, 0x4
000051 1283 BCF STATUS, 0x5
000052 1207 BCF PORTC, 0x4
19: delay_ms(10);
000053 300A MOVLW 0xa
000054 0A3 MOVWF 0x23
000055 200A CALL @delay_ms1

It is setting/resetting the pin correctly, and clearing the corresponding bit in the TRIS register (the default in standard_io mode).
You have something else wrong, other than the compiler, despite 'thinking' that this is the problem.
One 'thought', would be that if the supply is noisy, a brownout reset is being triggered, and maybe this is not enabled in the corresponding basic version.

Best Wishes
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 21, 2005 3:48 am     Reply with quote

Hi,
On the vcc pin i put a capacitor 10uF/16V and 100nF/50V and a diode zener 5v1, there isn't noise in supply
The brownout (Vbod from datasheet) is 2.1V
I have tried with these configurations :
#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, MCLR, NOCPD,PUT,NOBROWNOUT

#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, MCLR, NOCPD,PUT,BROWNOUT

#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOPROTECT, MCLR, NOCPD,NOPUT,NOBROWNOUT

#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO, NOPROTECT, MCLR, NOCPD,NOPUT,NOBROWNOUT

The OSC is always ok, but the program not run.
On the MCLR pin I read 5V, on Vcc 5V, the other pin are in tri-state
The PIC isn't broke, is new.
<<<The osc isn't calibrated>>> might be a problem..i don't know
it seems a mystery, Have you any idea??
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Jan 21, 2005 7:25 am     Reply with quote

Guard wrote:
Hi,
<<<The osc isn't calibrated>>> might be a problem..i don't know
it seems a mystery, Have you any idea??


Not if
Quote:
CLKOUT is ok, 1Mhz. I think that the osc function.


How are you determining C4 is not working and what pin are you looking at.
Guest








PostPosted: Fri Jan 21, 2005 7:43 am     Reply with quote

Hi,

Yes clkout is 1 Mhz
C4 is pin 6 i test it by oscilloscope, C4 not pulse
The probe is ok
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 21, 2005 7:54 am     Reply with quote

I have tested this code in asm but not function


list p=16f676 ; list directive to define processor
#include <p16F676.inc> ; processor specific variable definitions

errorlevel -302 ; suppress message 302 from list file

__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_CLKOUT

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.




;***** VARIABLE DEFINITIONS
w_temp EQU 0x20 ; variable used for context saving
status_temp EQU 0x21 ; variable used for context saving






;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program


ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt


; these first 4 instructions are not required if the internal oscillator is not used
main
; call 0x3FF ; retrieve factory calibration value
; bsf STATUS,RP0 ; set file register bank to 1
; movwf OSCCAL ; update register with factory cal value
; bcf STATUS,RP0 ; set file register bank to 0


; remaining code goes here

movlw 0;
movwf TRISC;
movlw 255;
movwf PORTC

; initialize eeprom locations

ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03






END ; directive 'end of program'
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Jan 21, 2005 7:59 am     Reply with quote

Retest with you BASIC program and see if it still works.
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 21, 2005 9:12 am     Reply with quote

I retested in Basic ,it functions
Observes this code:

1: #include <16F676.h>
000000 3000 MOVLW 0
000001 08A MOVWF PCLATH
000002 2804 GOTO 0x4
000003 000 NOP

000004 23FF CALL 0x3ff ----->Address for calibration
000005 1683 BSF STATUS, 0x5 ---------> memory bank 1
000006 090 MOVWF T1CON ---------> load in Timer1 control ??
000007 3000 MOVLW 0

000008 08A MOVWF PCLATH
000009 280A GOTO @cinit
2: #device adc=8
3: #use delay(clock=4000000)
4: #fuses NOWDT,INTRC, NOPROTECT, MCLR, NOCPD,PUT,BROWNOUT
5:
6:
7:
8: #ROM 0x3FF={0x3480}
9:
10: #byte PORTC = 7
11: #byte PORTA =5
12: #byte TRISC = 0x87
13:
14: /*
15: #byte OSCAL = 0X90
16: #byte OSCAL =0x8F
17: #define CALVALUE 0x9C
18: #byte trisc =0x87
19: 0x34 is RETLW op code and 0x9C is calibration value
20: #ROM 0x3ff = {0x349C}
21: OSCAL = CALVALUE;
22: */
23: void main()
24: {
00000A 184 CLRF FSR
00000B 301F MOVLW 0x1f
00000C 583 ANDWF STATUS, 0x1
00000D 131F BCF ADCON0, 0x6
00000E 3000 MOVLW 0
00000F 3807 IORLW 0x7
000010 1683 BSF STATUS, 0x5
000011 091 MOVWF 0x11
000012 3007 MOVLW 0x7
000013 1283 BCF STATUS, 0x5
000014 099 MOVWF CMCON
000015 1683 BSF STATUS, 0x5
000016 805 MOVF PORTA, 0
000017 1283 BCF STATUS, 0x5
000018 819 MOVF CMCON, 0
000019 118C BCF PIR1, 0x3
25:
26:
27: setup_adc_ports(NO_ANALOGS|VSS_VDD);
00001A 131F BCF ADCON0, 0x6
00001B 3000 MOVLW 0
00001C 1683 BSF STATUS, 0x5
00001D 091 MOVWF 0x11
28: setup_adc(ADC_OFF);
00001E 1283 BCF STATUS, 0x5
00001F 101F BCF ADCON0, 0
29: setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
000020 1683 BSF STATUS, 0x5
000021 801 MOVF TMR0, 0
000022 39C0 ANDLW 0xc0
000023 3808 IORLW 0x8
000024 081 MOVWF TMR0
30: setup_timer_1(T1_DISABLED);
000025 1283 BCF STATUS, 0x5
000026 190 CLRF T1CON
31: setup_comparator(NC_NC_NC_NC);
000027 3007 MOVLW 0x7
000028 099 MOVWF CMCON
000029 1683 BSF STATUS, 0x5
00002A 805 MOVF PORTA, 0
00002B 3003 MOVLW 0x3
00002C 1283 BCF STATUS, 0x5
00002D 0A0 MOVWF 0x20
00002E BA0 DECFSZ 0x20, 0x1
00002F 282E GOTO 0x2e
000030 819 MOVF CMCON, 0
000031 118C BCF PIR1, 0x3
32: setup_vref(FALSE);
000032 1683 BSF STATUS, 0x5
000033 199 CLRF CMCON
33:
34:
35: set_tris_C(0);
000034 3000 MOVLW 0
000035 087 MOVWF PORTC
36:
37: a:
38:
39: output_high(PIN_C0);
000036 1007 BCF PORTC, 0
000037 1283 BCF STATUS, 0x5
000038 1407 BSF PORTC, 0
40:
41:
42: goto a;
000039 1683 BSF STATUS, 0x5
00003A 2836 GOTO 0x36

the 0x3ff is empty
I put #ROM 0x3FF={0x3480}( retwl 0x80 for calibrate ), in the program memory it exist, but when I read micro , it becomes a NOP
I always use Picstart with os 3.11 and mplab 6.30
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Jan 21, 2005 9:20 am     Reply with quote

How do you program the part when you use the BASIC program?
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Fri Jan 21, 2005 9:29 am     Reply with quote

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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