Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Simple ASM programming glitch

Status
Not open for further replies.

JohnJohn20

Advanced Member level 4
Joined
Feb 2, 2012
Messages
111
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,377
I have programmed a 16F628A chip to do the following:
1. Wait for a normally high input (RA6) to go low
2. Then flash an led (connected to RA0) 3 times
3. Wait until the input (RA6) goes high again
4. Then go back to step 1.

Seems simple enough except that when when I make the input high at step 3. it goes back to step 1. and rather than waiting there for the input to go low, the program jumps to step 2. and flashes the led again.

If I make the input high before step 2. has finished then the program behaves as expected and waits at step 1..

I suspect that this issue has something to do with the input value not being updated in the chip but everything looks OK to me. Please check the program below.

Or, if the programming is OK, could it be the input is "bouncing" and false triggering. In this case what is a programming solution?

Thanks.

Here are the relevant parts of my ASM code:


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
INT_VAR        UDATA_SHR     
COUNT1                                  RES     1
COUNT2                                  RES     1
CycleCount                              RES     1
 
        ORG     0x000                   ; processor reset vector
        goto    main                    ; go to beginning of program
        ORG     0x004                   ; interrupt vector location 
                                                ; isr code can go here or be located as a call subroutine
                                                ; elsewhere
        retfie                                  ; Return from interrupt to main program
main
;****Set up port and constants**** 
        clrf    PORTA
        movlw   0x07
        movwf   CMCON           ; disable comparitors and set PORTs as I/O
        bcf             STATUS, RP1     ;changes RP1 bit to 0
        bsf             STATUS, RP0     ;changes RP0 bit to 1: -> 01 - change to bank 1
 
        movlw   0xFE    ;11111110
        movwf   TRISA   ; set RA0 as output and RA<1:7> as input
                                        ; RA0 OUTPUT : LED
                                        ; RA6 INPUT : Normally High = Wait
        bcf             STATUS, RP1     ;changes RP1 bit to 0
        bcf             STATUS, RP0     ;changes RP0 bit to 0: -> 00 - back to bank 0
Start
        clrf    CycleCount      ; reset CycleCount to 0x00
        btfsc   PORTA,6         ; if RA6 high
        goto    Start                   ; then cycle back to start
FlashLed                                ; else flash LED
        bsf             PORTA,0 ; turn on LED
        call    QuarterSecDelay ; wait
        call    QuarterSecDelay ; wait
        bcf             PORTA,0 ; turn off LED
        call    QuarterSecDelay ; wait
        call    QuarterSecDelay ; wait
        incf    CycleCount,1            ; increase CountCycle by 1
CheckFlashCount         ; 
        movlw   0x03
        subwf   CycleCount,w    ; If CycleCount - w < 0 then STATUS,C = 0
        btfss   STATUS,C                        ; If CycleCount  < 3 (ie STATUS,C = 0)
        goto    FlashLed                        ; Then FlashLed again
CycleReset                                      ; else (CycleCount  = 3) reset everything
        btfss   PORTA,6                 ; if RA6 low
        goto    CycleReset                      ; then loop around until RA6 goes high again
        goto    Start                           ; else go back to Start
QuarterSecDelay
        decfsz  COUNT1,1        
        goto    QuarterSecDelay
        decfsz  COUNT2,1        
        goto    QuarterSecDelay
        return
 
        END                       ; directive 'end of program'


- - - Updated - - -

Yes well. It was indeed contact bounce. Solved it by putting a delay just before the goto Start instruction.
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top