|
|
View previous topic :: View next topic |
Author |
Message |
Wipster
Joined: 09 Oct 2008 Posts: 16
|
Using CLKIN as output on an 12F1840 |
Posted: Tue Nov 15, 2011 8:52 am |
|
|
Hi all,
I have been looking at this for half of this afternoon and I cant seem to get it right.
The compiler in use is v4.124.
I am trying to use the CLKIN pin (PIN_A5) as an output on the 12F1840, this output is driving an LED. I have a very simple flashing program loaded however it doesn't seem to light up, I have verified the program works when using another pin such as PIN_A2 however.
I have also been trying to get the RS232 to work coming out of PIN_A4 which is the on board UART1, however I'm not getting any dice with that either, something is amiss.
Here is the super simple code
Code: | #include <12F1840.h>
#FUSES INTRC_IO,NOWDT,NOPUT,MCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOCLKOUT,IESO,NOFCMEN,STVREN,BORV19,NOLVP
#USE DELAY(internal=8Mhz)
void
main (void)
{
while (1)
{
output_high(PIN_A5);
delay_ms(1000);
output_low(PIN_A5);
delay_ms(1000);
}
} |
And here is the circuit diagram for the PIC, also super simple.
|
|
|
Wipster
Joined: 09 Oct 2008 Posts: 16
|
|
Posted: Tue Nov 15, 2011 10:14 am |
|
|
After a bit more poking around, I have found that the pin is sitting at a steady 3.8Vish.
From looking at the status registers LATA is oscillating, however PORTA and the pin voltage are not.
Found that if I assign the flashing to another pin then short that pin with this one, the led flashes as expected. Is there something odd about the drain on this pin? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Nov 15, 2011 10:25 am |
|
|
Since that pin can be used for a LOT of other purposes, I suspect the compiler may have it 'defaulted' to one of those purposes.
Dump the listing( .lst) and see what code is generated.Maybe it gets 'setup' as the default UART or PWM pin ? |
|
|
Wipster
Joined: 09 Oct 2008 Posts: 16
|
|
Posted: Tue Nov 15, 2011 10:36 am |
|
|
Hmmm yeh I did think about that, in that area can be controlled by the APFCON registers but I have tried explicitly stating those and nothing still.
The Electrical specs says max drain current on any IO pin is 25mA so I'm within that at 12mA.
I cant see anything untoward in the disassembly but its been a while since I have been this low level, can you?
Code: |
1: #include <12F1840.h>
000 0000 NOP
001 3180 MOVLP 0
002 2812 GOTO 0x12
2:
3: //#FUSES NONE
4: #FUSES INTRC_IO,NOWDT,NOPUT,MCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOCLKOUT,IESO,NOFCMEN,STVREN,BORV19,NOLVP
5: #USE DELAY (INTERNAL=2MHZ)
003 3020 MOVLW 0x20
004 0085 MOVWF 0x5
005 3006 MOVLW 0x6
006 0084 MOVWF 0x4
007 0800 MOVF 0, W
008 1903 BTFSC 0x3, 0x2
009 2811 GOTO 0x11
00A 30A5 MOVLW 0xa5
00B 00A0 MOVWF 0x20
00C 0BA0 DECFSZ 0x20, F
00D 280C GOTO 0xc
00E 0000 NOP
00F 0B80 DECFSZ 0, F
010 280A GOTO 0xa
011 0008 RETURN
6:
7: #byte APFCON = getenv("SFR:APFCON")
8: #bit RXDTSEL = APFCON.7
9: #bit TXCKSEL = APFCON.2
10: #bit CCP1SEL = APFCON.0
11:
12: #byte OPTION_REG = getenv("SFR:OPTION_REG")
13: #bit WPUEN = OPTION_REG.7
14:
15: void
16: main (void)
17: {
012 0185 CLRF 0x5
013 0184 CLRF 0x4
014 301F MOVLW 0x1f
015 0583 ANDWF 0x3, F
016 3062 MOVLW 0x62
017 0021 MOVLB 0x1
018 0099 MOVWF 0x19
019 0023 MOVLB 0x3
01A 018C CLRF 0xc
01B 0022 MOVLB 0x2
01C 0192 CLRF 0x12
01D 0191 CLRF 0x11
01E 0194 CLRF 0x14
01F 0193 CLRF 0x13
18: TXCKSEL = 1;
020 151D BSF 0x1d, 0x2
19: CCP1SEL = 1;
021 141D BSF 0x1d, 0
20: RXDTSEL = 0;
022 139D BCF 0x1d, 0x7
21:
22: WPUEN = 1;
023 0021 MOVLB 0x1
024 1795 BSF 0x15, 0x7
23:
24: while (1)
25: {
26: output_high(PIN_A5);
025 128C BCF 0xc, 0x5
026 0022 MOVLB 0x2
027 168C BSF 0xc, 0x5
27: delay_ms(1000);
028 3004 MOVLW 0x4
029 0020 MOVLB 0
02A 00A5 MOVWF 0x25
02B 30FA MOVLW 0xfa
02C 00A6 MOVWF 0x26
02D 2003 CALL 0x3
02E 0BA5 DECFSZ 0x25, F
02F 282B GOTO 0x2b
28: output_low(PIN_A5);
030 0021 MOVLB 0x1
031 128C BCF 0xc, 0x5
032 0022 MOVLB 0x2
033 128C BCF 0xc, 0x5
29: delay_ms(1000);
034 3004 MOVLW 0x4
035 0020 MOVLB 0
036 00A5 MOVWF 0x25
037 30FA MOVLW 0xfa
038 00A6 MOVWF 0x26
039 2003 CALL 0x3
03A 0BA5 DECFSZ 0x25, F
03B 2837 GOTO 0x37
30: }
03C 0021 MOVLB 0x1
03D 2825 GOTO 0x25
03E 283E GOTO 0x3e |
|
|
|
Wipster
Joined: 09 Oct 2008 Posts: 16
|
|
Posted: Tue Nov 15, 2011 10:59 am |
|
|
Ok progress, connected a new board and flashing light is a go. So it seems there was a problem with the circuit board, typical.
Now on to the UART, some reason that's outputting 'gDg ge @g:g' etc consistently random crap, when I do a printf("1");
Fun times. |
|
|
|
|
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
|