just noticed the wend fell off
Code:while 1 ; loop forever wend
just noticed the wend fell off
Code:while 1 ; loop forever wend
The settings are the way they are because that code is from a much larger piece of code. I am utilizing 23 I/O pins, so those are the settings for those pins.
Since the larger portion of code was not working, I dumbed it down to see where my problem was. It's a lot easier for me to diagnose this way. I just can't figure out why it resets itself after the last command. I even put a loop at the end which would only exit after a button was pressed. It would hold there for one time and then after the button was pressed once, it would run through the sequencing and reset as stated earlier without holding in the hold loop.
an erased chip is all nop's
a program not in a closed loop will execute all the remaining nop's till it hits the end of pgm memory, it then wraps back to location 0000 ie looks like a reset
adcon1=15 is an invalid setting and may cause issues
I had assumed the leds were on b0,b1, a0,a1 my mistake in the tris settings
Actually, I tried multiple settings. I searched throughout this site and even found one instance where Darrel suggested adcon1 = 15, so I tried that. After my post, I changed it to:
The end code I had after the last LED pause was:Code:ADCON1 = %00001110 ' set to digital outputs
As stated, when the program is initially run, the program waits until the button was pressed. Once pressed, it then runs through the sequence continuously, never stopping at the while loop.Code:while program = 1 pause 100 wend relay1 = 0 relay2 = 0 relay3 = 0 relay4 = 0 led1 = 0 led2 = 0 led3 = 0 led4 = 0 goto action
Now, I did put in the necessary variable at the top of the code so it would acknowledge the button and when it would be pressed, I'm just out of ideas. Anybody have any?
Thanks,
Tony
Simplify, blink one LED on/off.
Robert
Edit: I had posted code for this pic but can't find it (on cell phone).
that snippet shows no possible way to exit the while loop . how CAN THE PROGRAM VAR EVER CHANGE ???
ADCON1 = %00001110 ' set to digital outputs IS STILL WRONG read the data sheet adcon1 has no effect on setting inputs to digital at all
post the whole test code
The current code is written as such: Turn on each LED in sequence and leave them on until the button is pressed. It is a pull down input. When the button is pressed, turn off all the LEDs and repeat the sequence.Code:;----[18F25K22 Hardware Configuration]------------------------------------------ #IF __PROCESSOR__ = "18F25K22" #DEFINE MCU_FOUND 1 #CONFIG CONFIG FOSC = INTIO67 ; Internal oscillator block CONFIG PLLCFG = OFF ; Oscillator used directly CONFIG PRICLKEN = ON ; Primary clock can be disabled by software CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled CONFIG IESO = OFF ; Oscillator Switchover mode disabled CONFIG PWRTEN = OFF ; Power up timer disabled CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled) CONFIG BORV = 190 ; VBOR set to 1.90 V nominal CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect CONFIG WDTPS = 32768 ; 1:32768 CONFIG CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1 CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset CONFIG CCP3MX = PORTB5 ; P3A/CCP3 input/output is multiplexed with RB5 CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status CONFIG T3CMX = PORTC0 ; T3CKI is on RC0 CONFIG P2BMX = PORTB5 ; P2B is on RB5 CONFIG MCLRE = INTMCLR ; RE3 input pin enabled; MCLR disabled CONFIG STVREN = ON ; Stack full/underflow will cause Reset CONFIG LVP = OFF ; Single-Supply ICSP disabled CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode) CONFIG DEBUG = OFF ; Disabled CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected CONFIG CPD = OFF ; Data EEPROM not code-protected CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected CONFIG WRTD = OFF ; Data EEPROM not write-protected CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks CONFIG EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks #ENDCONFIG #ENDIF ;----[Verify Configs have been specified for Selected Processor]---------------- ; Note: Only include this routine once, after all #CONFIG blocks #IFNDEF MCU_FOUND #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]" #ENDIF ' -----[ Initialization ]------------------------------------------------------- Reset: OSCCON = %01010000 ' 4MHz ADCON1 = %00001110 ' set to digital outputs TRISA = %00000000 ' sets pin as input (1) or output (0) TRISB = %00000001 ' sets pin as input (1) or output (0) TRISC = %10001100 ' sets pin as input (1) or output (0) PORTA = %00000000 ' sets outputs as high (1) or low (0) PORTB = %00000000 ' sets outputs as high (1) or low (0) PORTC = %00000000 ' sets outputs as high (1) or low (0) ' -----[ Variables ]------------------------------------------------------------ led1 var porta.1 ' LED 1 led2 var porta.2 ' LED 2 led3 var portb.1 ' LED 3 led4 var portb.2 ' LED 4 program var porta.0 ' button to restart sequence action: led1 = 1 pause 500 led2 = 1 pause 500 led3 = 1 pause 500 led4 = 1 pause 500 while program = 1 ' loop here until the button is pressed pause 100 wend led1 = 0 led2 = 0 led3 = 0 led4 = 0 goto action
Right now, LED1 turns on and then when LED2 goes to turn on, LED1 turns off. LEDs 2-4 sequence on and stay on, but LED1 stays off. On the first run, the LEDs turn on and stay on until the button is pressed. After the initial press, the LEDs turn on in sequence (except for LED1) and once LED4 is lit, they all turn off and the sequence in repeated.
Can't figure it out unless it's because of my pins not all being set to digital. I'm asking for help on what the proper code is for setting them all to digital. I keep finding posts where people say read the datasheet. I've read the datasheet and I've entered what I think it is telling me for how to set the pins to all digital. I'm now asking for help.
GOOGLE "PIC READ MODIFY WRITE"
Code:;----[18F25K22 Hardware Configuration]------------------------------------------ #IF __PROCESSOR__ = "18F25K22" #DEFINE MCU_FOUND 1 #CONFIG CONFIG FOSC = INTIO67 ; Internal oscillator block CONFIG PLLCFG = OFF ; Oscillator used directly CONFIG PRICLKEN = ON ; Primary clock can be disabled by software CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled CONFIG IESO = OFF ; Oscillator Switchover mode disabled CONFIG PWRTEN = OFF ; Power up timer disabled CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled) CONFIG BORV = 190 ; VBOR set to 1.90 V nominal CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect CONFIG WDTPS = 32768 ; 1:32768 CONFIG CCP2MX = PORTC1 ; CCP2 input/output is multiplexed with RC1 CONFIG PBADEN = OFF ; PORTB<5:0> pins are configured as digital I/O on Reset CONFIG CCP3MX = PORTB5 ; P3A/CCP3 input/output is multiplexed with RB5 CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status CONFIG T3CMX = PORTC0 ; T3CKI is on RC0 CONFIG P2BMX = PORTB5 ; P2B is on RB5 CONFIG MCLRE = INTMCLR ; RE3 input pin enabled; MCLR disabled CONFIG STVREN = ON ; Stack full/underflow will cause Reset CONFIG LVP = OFF ; Single-Supply ICSP disabled CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode) CONFIG DEBUG = OFF ; Disabled CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) not code-protected CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) not code-protected CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) not code-protected CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) not code-protected CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected CONFIG CPD = OFF ; Data EEPROM not code-protected CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) not write-protected CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) not write-protected CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) not write-protected CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) not write-protected CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected CONFIG WRTD = OFF ; Data EEPROM not write-protected CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) not protected from table reads executed in other blocks CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) not protected from table reads executed in other blocks CONFIG EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks #ENDCONFIG #ENDIF ;----[Verify Configs have been specified for Selected Processor]---------------- ; Note: Only include this routine once, after all #CONFIG blocks #IFNDEF MCU_FOUND #ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]" #ENDIF ' -----[ Initialization ]------------------------------------------------------- Reset: OSCCON = %01010000 ' 4MHz ADCON1 = %00001110 ' set to digital outputs this is totally wrong TRISA = %00000000 ' sets pin as input (1) or output (0) TRISB = %00000001 ' sets pin as input (1) or output (0) TRISC = %10001100 ' sets pin as input (1) or output (0) PORTA = %00000000 ' sets outputs as high (1) or low (0) PORTB = %00000000 ' sets outputs as high (1) or low (0) PORTC = %00000000 ' sets outputs as high (1) or low (0) ANSELA=0 WILL SET PORTA DIGITAL ANSELB=0 WILL SET PORTB DIGITAL ' -----[ Variables ]------------------------------------------------------------ led1 var porta.1 ' LED 1 JUST ASKING FOR READ MODIFY WRITE ISSUES led2 var porta.2 ' LED 2 led3 var portb.1 ' LED 3 led4 var portb.2 ' LED 4 led1 var LATA.1 ' LED 1 CAN ELIMINATE READ MODIFY WRITE ISSUES led2 var LATA.2 ' LED 2 led3 var LATB.1 ' LED 3 led4 var LATB.2 ' LED 4 program var porta.0 ' button to restart sequence action: led1 = 1 pause 500 led2 = 1 pause 500 led3 = 1 pause 500 led4 = 1 pause 500 while program = 1 ' loop here until the button is pressed pause 100 wend led1 = 0 led2 = 0 led3 = 0 led4 = 0 goto action
Last edited by richard; - 22nd November 2014 at 22:49.
Hi
Aside from the analog port issues..... If you want the LED's to sequence, you need to put them low at some point otherwise they all going to be mostly high all the time ?
Maybe as others far wiser than me will suggest (Robert)..... get the code to turn one LED on and off (Flash)
Move this simple code around the ports.. Then once you know this is working OK... Progress on further.
flash: ledx high
pause 500
ledx low
pause 500
goto flash
BR
Andy
Bookmarks