Alright I am working with USB here, I'm using a PIC18F4550 with a 20MHz HS crystal, pll etc is all running fine considering I can talk to it via USB perfectly (for the most part). My issue is that I can not get the RAM to clear old variables from before when the mC was reset. here is the gist of the code I am using:
Now what it's designed to do is receive a sleep interrupt that puts the controller to sleep after attempting to send one last packet of data to the computer. After 30 tries it forces the controller to sleep, bypassing the task of sending that last packet. So now that the uC is sleeping, I hit the resume interrupt once. This wakes the controller up and it's now waiting for either another reset interrupt or another sleep interrupt. If a second reset interrupt is received the controller should then reset the whole system and start the entire program over. The problem I have is that the uC is not reseting the variables even if I try to clear them at the beginning of the program. These variables not being cleared creaates a whole world of problems when my software goes to try and talk to the PIC again. ThanksCode:'Oscillator Settings: DEFINE OSC 48 DEFINE NO_CLRWDT 1 'low portc.6 'Not entirely sure what I made this for again....keep it for now.... 'Setup Registers: CMCON = 7 ADCON1 = %00111011 TRISA = $0f INCLUDE "DT_INTS-18.bas" ; Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts 'Includes: INCLUDE "modedefs.bas" include "defsvars.bas" ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT2_INT, _resume_sleep, PBP, yes INT_Handler INT1_INT, _goto_sleep, PBP, yes INT_Handler TMR1_INT, _Sleep_loop_timer, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM '@ INT_DISABLE INT2_INT ; enable external (INT) interrupts '@ INT_DISABLE INT1_INT @ INT_ENABLE INT2_INT ; enable external (INT) interrupts @ INT_ENABLE INT1_INT T1CON = $31 ; Prescaler = 8, TMR1ON @ INT_ENABLE TMR1_INT '@ INT_DISABLE TMR1_INT 'TMR1L = $01 'TMR1H = $00 'Main Initializations main: pause 5000 lcdout $FE, 1, "System init" for index = 0 to 64 'Clear Output USB Buffer bufferout[index] = "0" '* next '* for index = 0 to 64 'Clear Input USB Buffer bufferin[index] = "0" '* next '* sys_sleep_flag = 0 'Reset flag sys_reset_flag = 0 'Reset flag unlocked = 0 data_mode = 0 counter = 0 'high BL 'Turn on Backlight pause 10 'high V_Supply '* pause 10 high EEE_Power '* high EEE_switch 'Turn on computer pause 500 '* low EEE_switch '* 'gosub StartEngine '* ' gosub Initlcd 'Initialize LCD ' gosub relaytest '* gosub temp_init 'Initialize Temperature Sensors 'gosub SETLCDBG '* ' gosub starting_usb '* goto usbstart 'Initialize USB and run routines stop end goto_sleep: 'Sleep Interrupt sys_int_counter = 0 '* sys_sleep_flag = 1 '* sys_reset_flag = 0 @ INT_RETURN resume_sleep: 'Resume Interrupt LCDOUT $FE, $1, "RESET 1" if sys_reset_flag = 0 then if ENGINE_STAT = 0 then sys_int_counter = 0 '* sys_reset_flag = 1 '* sys_sleep_flag = 0 @ INT_RETURN endif endif if sys_reset_flag = 1 then '@ INT_ENABLE TMR1_INT sys_sleep_flag = 0 UCON.3 = 1 '* LCDOUT $FE, $1, $fe, $c0, "RESET 2" '@ INT_ENABLE TMR1_INT pause 1000 @ reset endif @ INT_RETURN Sleep_loop_timer: counter = counter + 1 if ENGINE_STAT = 1 then high portb.7 sys_sleep_flag = 0 ENDIF if ENGINE_STAT = 0 then low portb.7 ENDIF if sys_sleep_flag = 1 then if ENGINE_STAT = 0 then low portb.7 @ INT_ENABLE INT2_INT ; enable external (INT) interrupts @ INT_ENABLE INT1_INT bufferout(0) = $07 bufferout(1) = $01 if counter < 30 then USBOut 1, bufferout, 64, sleep_loop_timer endif pause 100 sys_int_counter = 1 UCON.3 = 0 'gosub entering_sleep low V_Supply low EEE_Power low BL sys_reset_flag = 0 unlocked = 0 @ INT_DISABLE TMR1_INT LCDOUT $FE, $1, "Sleep" @ sleep 'goto waiting_loop endif if ENGINE_STAT = 1 then high portb.7 @ INT_DISABLE INT2_INT ; enable external (INT) interrupts @ INT_DISABLE INT1_INT sys_sleep_flag = 0 sys_reset_flag = 0 endif endif @ INT_RETURN 'include "fontruntime.bas" 'Include "lcdstring.bas" 'include "LCDRoutines.bas" include "RelayControlRoutines.bas" Include "ja_desc.bas" include "USB_Routines.bas" include "I2C_Routines.bas" include "ADC_Routines.bas"
Also, props to Darrel Taylor for the interrupts work. It's amazing.




Bookmarks