Hi, I am facing unexpected behaviour from my PIC.
I am trying to run a simple code for accepting serial data & checking the state of input pins in between using DT_Interrupts. I have tried to debug by blinking some leds on PICKit only but result is dissapointing again and again. Please help...
I have attached the code here:
The leds at portc.0 & 1 should toggle at regular interval. BUT they show random behaviour, sometimes steady on, then off, then just 1 is on and so on.Code:@ __Config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP & _CPD pin13 VAR PortA.0 pin12 VAR PortA.1 pin11 VAR PortA.2 'pin4 VAR PortA.3 pin3 VAR PortA.4 pin2 VAR PortA.5 pin10 VAR PortC.0 pin9 VAR PortC.1 pin8 VAR PortC.2 pin7 VAR PortC.3 pin6 VAR PortC.4 pin5 VAR PortC.5 '----------Variables declared here---------------- code VAR byte Include "modedefs.bas" INCLUDE "DT_INTS-14.bas" INCLUDE "ReEnterPBP.bas" '----------Processor Initialisation--------------- PAUSE 50 TRISA = %111111 TRISC = 0 PORTC = 0 CMCON = 7 ANSEL = 0 OPTION_REG.7=0 WPUA=%110111 ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _CHECK, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM T1CON=$31 BB: @ INT_ENABLE TMR1_INT '--------------Main Program starts here----------- start: Serin PORTA.3,N2400,["o9"],code @ INT_DISABLE TMR1_INT pause 500 if code=42 then pin5=1 if code=44 then pin6=1 '.........and so on for portc goto BB CHECK: toggle portc.0 toggle portc.1 if pin2=0 then pin5=0 while pin2=0 wend if pin3=0 then pin6=0 while pin3=0 wend if pin13=0 then PORTC=0 while pin13=0 wend @ INT_RETURN
when I remove especially this statement 'if pin13=0 then PORTC=0
while pin13=0
wend', chances are good that LEDs will behave normal.
My DT_INTS-14.bas looks like this:
I assume because of this problem only, the serin command is not acting as well when it receives the data.Code:wsave var byte $20 SYSTEM ' location for W if in bank0 ;wsave var byte $70 SYSTEM ' alternate save location for W ' if using $70, comment out wsave1-3 ' ' --- IF any of these three lines cause an error ?? ---------------------------- ' Comment them out to fix the problem ---- ' -- It depends on which Chip you are using, as to which variables are needed -- ;wsave1 var byte $A0 SYSTEM ' location for W if in bank1 ;wsave2 var byte $120 SYSTEM ' location for W if in bank2 ;wsave3 var byte $1A0 SYSTEM ' location for W if in bank3
Can someone please advise me what am I doing wrong here...?Thanks
__________________
___________________
WHY things get boring when they work just fine?



The interrupt and whatever is in ISR, is working fine. Though the weak internal pullup for PortA.0 & 1 didn't worked (I wonder why), but I managed with external pullups for them. 


Bookmarks