|
|
View previous topic :: View next topic |
Author |
Message |
prayami
Joined: 22 Dec 2004 Posts: 78
|
Problem with 12F683 |
Posted: Mon Dec 12, 2005 7:08 pm |
|
|
Hi..I am using 12F683 to generate 10Khz pulse. I am using CCS PCM C Compiler, Version 3.206 . I tried a lot but could not generate output
pulses on PIN_A4 . Here is the code:
Can anybody figure out the problem please.....
Code: |
#CASE
#include <12F683.h>
#fuses INTRC_IO,NOBROWNOUT,NOMCLR,NOWDT,PROTECT,PUT,NOCPD,NOIESO,NOFCMEN
#use delay(clock=4000000)
int1 High=0;
void main() {
setup_oscillator(OSC_4MHZ); // select 4MHz internal clock
set_tris_a(0x2B); // A0-A5 Output
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC); // Disable comparators
setup_vref(FALSE);
output_low(PIN_A4); // INT/HOLD signal
delay_us(50);
while(TRUE) {
if(High==0)
{
output_high(PIN_A4);
High=1;
}
else
{
High=0;
output_low(PIN_A4);
}//if(High==0)
delay_us(29);
}//while(TRUE)
}//main
|
and here is the .lst file.....
Code: |
CCS PCM C Compiler, Version 3.206, 24476 13-Dec-05 14:02
Filename: Knock_IntHold.LST
ROM used: 88 words (4%)
Largest free fragment is 1960
RAM used: 7 (5%) at main() level
7 (5%) worst case
Stack: 0 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 004
0003: NOP
0004: MOVLW 07
0005: MOVWF 0A
0006: CALL 7FF
0007: BSF 03.5
0008: MOVWF 10
0009: MOVLW 00
000A: MOVWF 0A
000B: GOTO 00C
....................
.................... #CASE
.................... #include <12F683.h>
.................... //////// Standard Header file for the PIC12F683 device ////////////////
.................... #device PIC12F683
.................... #list
....................
.................... #fuses INTRC_IO,NOBROWNOUT,NOMCLR,NOWDT,PROTECT,PUT,NOCPD,NOIESO,NOFCMEN
....................
.................... #use delay(clock=4000000)
....................
.................... int1 High=0;
*
001B: BCF 03.5
001C: BCF 25.0
....................
.................... void main() {
....................
*
000C: CLRF 04
000D: MOVLW 1F
000E: ANDWF 03,F
000F: BCF 1F.6
0010: BSF 03.5
0011: BSF 1F.0
0012: BSF 1F.1
0013: BSF 1F.2
0014: BSF 1F.3
0015: MOVLW 07
0016: BCF 03.5
0017: MOVWF 1F
0018: MOVLW 60
0019: BSF 03.5
001A: MOVWF 0F
....................
.................... setup_oscillator(OSC_4MHZ); // select 4MHz internal clock
*
001D: MOVLW 60
001E: BSF 03.5
001F: MOVWF 0F
.................... set_tris_a(0x2B); // A0-A5 Output
0020: MOVLW 2B
0021: TRIS 5
....................
.................... setup_adc(ADC_OFF);
0022: BCF 03.5
0023: BCF 1F.0
.................... setup_adc_ports(NO_ANALOGS);
0024: BCF 1F.6
0025: BSF 03.5
0026: BCF 1F.0
0027: BCF 1F.1
0028: BCF 1F.2
0029: BCF 1F.3
.................... setup_comparator(NC_NC_NC_NC); // Disable comparators
002A: MOVLW 07
002B: BCF 03.5
002C: MOVWF 19
002D: BSF 03.5
002E: MOVF 05,W
002F: MOVLW 03
0030: BCF 03.5
0031: MOVWF 20
0032: DECFSZ 20,F
0033: GOTO 032
0034: MOVF 19,W
0035: BCF 0C.3
.................... setup_vref(FALSE);
0036: BSF 03.5
0037: CLRF 19
....................
.................... output_low(PIN_A4); // INT/HOLD signal
0038: BCF 05.4
0039: BCF 03.5
003A: BCF 05.4
....................
....................
.................... delay_us(50);
003B: MOVLW 10
003C: MOVWF 20
003D: DECFSZ 20,F
003E: GOTO 03D
003F: NOP
....................
.................... while(TRUE) {
....................
.................... if(High==0)
0040: MOVLW 00
0041: BTFSC 25.0
0042: MOVLW 01
0043: XORLW 00
0044: BTFSS 03.2
0045: GOTO 04C
.................... {
.................... output_high(PIN_A4);
0046: BSF 03.5
0047: BCF 05.4
0048: BCF 03.5
0049: BSF 05.4
.................... High=1;
004A: BSF 25.0
.................... }
.................... else
004B: GOTO 051
.................... {
.................... High=0;
004C: BCF 25.0
.................... output_low(PIN_A4);
004D: BSF 03.5
004E: BCF 05.4
004F: BCF 03.5
0050: BCF 05.4
.................... }//if(High==0)
....................
.................... delay_us(29);
0051: MOVLW 09
0052: MOVWF 20
0053: DECFSZ 20,F
0054: GOTO 053
0055: NOP
....................
....................
....................
.................... }//while(TRUE)
0056: GOTO 040
....................
.................... }//main
....................
....................
0057: SLEEP
Configuration Fuses:
Word 1: 3084 NOWDT NOCPD PROTECT NOMCLR PUT INTRC_IO NOBROWNOUT NOIESO NOFCMEN
|
Thanks... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 12, 2005 7:55 pm |
|
|
Quote: | I tried a lot but could not generate output pulses on PIN_A4 . |
Your version of the compiler has a bug for the 12F683. Notice the
line in bold, below. It's calling 0x7FF, as if there is a RETLW instruction
there, with an OSCCAL value. But for the 12F683, this feature doesn't
exist. So doing this will cause the program to crash.
Quote: |
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 004
0003: NOP
0004: MOVLW 07
0005: MOVWF 0A
0006: CALL 7FF
0007: BSF 03.5
0008: MOVWF 10
0009: MOVLW 00
000A: MOVWF 0A
000B: GOTO 00C
|
To fix the problem, use the #rom directive to put a RETLW 00
instruction at address 0x7FF. This will load 0x00 into the OSCTUNE
register (which is the default state), and your program will now run OK.
Add the line shown in bold, below:
Quote: |
#CASE
#include <12F683.h>
#fuses INTRC_IO,NOBROWNOUT,NOMCLR,NOWDT,PROTECT,PUT,NOCPD,NOIESO,NOFCMEN
#use delay(clock=4000000)
#rom 0x7FF = {0x3400}
|
|
|
|
prayami
Joined: 22 Dec 2004 Posts: 78
|
|
Posted: Mon Dec 12, 2005 8:02 pm |
|
|
Thanks PCM programmer. It is working now with adding a one line you
suggested.
You are greate.... |
|
|
|
|
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
|