Jump to content
43oh

7-Segment, w/ push-Button Input


Recommended Posts

Hello, all. I need help on the following code. The msp430 is controlling a 7-segment display. After it runs thru 0-F, It stops at 0. The 4 input buttons act as binary numbers(0 or 1). I can only get the program to take one button input, thus only allowing

 

1000,0100,0010,and 0001. When i need 0001,0010,0011,0100,0101, etc. What can I do to perform this task?

 

Thank you very much for your time.
;   
;   This code provides a trivial example for demonstrating writing to the
;   1-digit display- mainly this will quickly cycle through each segment
;   one at a time, then run a quick test of the 4 pushbuttons, by turning on
;   the symbol 0,1,2,or 3 to indicate which one (only one) PB is pressed.   
;   Only capable of testing one pushbutton at a time, not combinations
;    
;      
;
;   Target: TI LaunchPad development board with MSP430G2553 device with the
;    custom  1 digit expansion Display Board installed
;

;
;       HW I/O assignments:

;
;       P1.0    (output) LED1 LaunchPad bd (active high)
;       P1.1    (input)  pushbutton (top) (active low) expansion bd
;       P1.2    (input)  pushbutton (second from top) (active low) expansion bd
;       P1.3    (input)  pushbutton on LaunchPad bd (active low)
;       P1.4    (input) pushbutton (third from top) (active low) expansion bd
;       P1.5    (input) pushbutton (bottom) (active low) expansion bd
;       P1.6    (output) LED2 LaunchPad bd (active high)  
;       P1.7    (not used)  
;
;       P2.0    (output) Segment A (active high) drives display board
;       P2.1    (output) Segment B (active high) drives display board
;       P2.2    (output) Segment C (active high) drives display board
;       P2.3    (output) Segment D (active high) drives display board
;       P2.4    (output) Segment E (active high) drives display board
;       P2.5    (output) Segment F (active high) drives display board
;       P2.6    (output) Segment G (active high) drives display board
;       P2.7    (output) Segment DP (active high) drives display board
;
;
;
;*******************************************************************************
#include  "msp430g2553.h"
;-------------------------------------------------------------------------------
; Definition of Constants
;-------------------------------------------------------------------------------

LONG_DELAY      EQU     65535  ; max 16 bit value (FFFFh)
;LONG_DELAY      EQU     600  ; max 16 bit value (FFFFh)
SHORT_DELAY     EQU     5000  ;

TIMER_A_COUNT_1   EQU   1000   ; set count value in TimerA_0  

MAX_TIMER_COUNT  EQU    50    ; number of Timer Interrupts that have to occur

SEG_A         EQU     %00000001 ; Port pin position P2.0
SEG_B         EQU     %00000010 ; Port pin position P2.1
SEG_C         EQU     %00000100 ; Port pin position P2.2
SEG_D         EQU     %00001000 ; Port pin position P2.3
SEG_E         EQU     %00010000 ; Port pin position P2.4
SEG_F         EQU     %00100000 ; Port pin position P2.5
SEG_G         EQU     %01000000 ; Port pin position P2.6
SEG_DP        EQU     %10000000 ; Port pin position P2.7


PB_0         EQU     %00000010 ; Port pin position P1.1
PB_1         EQU     %00000100 ; Port pin position P1.2   
PB_2         EQU     %00010000 ; Port pin position P1.4   
PB_3         EQU     %00100000 ; Port pin position P1.5
PB_LPBD      EQU     %00001000 ; Port pin position P1.3 (on LaunchPad bd)



SEG_PORT         EQU     P2OUT
PB_PORT          EQU     P1IN

ZERO            EQU     %00111111
ONE             EQU     %00000110
TWO             EQU     %01011011
THREE           EQU     %01001111
FOUR            EQU     %01100110
FIVE            EQU     %01101101
SIX             EQU     %01111100
SEVEN           EQU     %00000111
EIGHT           EQU     %01111111
NINE            EQU     %01100111
Letter_A        EQU     %01110111
Letter_B        EQU     %01111100
Letter_C        EQU     %00111001
Letter_D        EQU     %01011110
Letter_E        EQU     %01111001
Letter_F        EQU     %01110001


;-------------------------------------------------------------------------------
; Definition of Variables
;-------------------------------------------------------------------------------

                ORG   0200h     ; beginning of RAM space (necessary statement)

; no variables used in this simple example

;-------------------------------------------------------------------------------
            ORG     0C000h                  ; Program Reset (prog memory start)
                                            ; this is Program memory start
                                            ; address for MSP430G2553 (16K)
;-------------------------------------------------------------------------------
RESET       mov.w   #0400h,SP        ; Initialize stackpointer(to end of RAM +1)
                                     ; RAM is 512 bytes, last position is 3FFh
                                     
StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT

SetupP2     ;;;mov.b   #0FFh, &P1DIR  ; all as outputs          
           mov.b   #0FFh, &P2DIR ; all as outputs to drive 7-seg LED
                                                            
           bic.b    #0C0h, &P2SEL   ; Clears the P2SEL bits so that
                                        ; P2.6 and P2.7 function as GPIO pins
                                        
           mov.b    #0BEh, &P1REN    ;turn on the internal resistor for PB's
           mov.b    #0BEh, &P1OUT    ; set the resistors to Pullup mode                                        
          
           
           ; turn off all the segments
           clr.b  &SEG_PORT
          
           
DisplayTop   

           mov.b #ONE, &SEG_PORT  ; crude approach

           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long           
           
           mov.b #TWO, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long            
           
           mov.b #THREE, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long            
           
           mov.b #FOUR, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long            
           
           mov.b #FIVE, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long            
           
           mov.b #SIX, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long            
           
           mov.b #SEVEN, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long           
           
           mov.b #EIGHT, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long  
           
           mov.b #NINE, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           
           mov.b #Letter_A, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           
           mov.b #Letter_B, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           
           mov.b #Letter_C, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
          
           mov.b #Letter_D, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long  
           
           mov.b #Letter_E, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
          
           mov.b #Letter_F, &SEG_PORT
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long
           call #Delay_Long  
           
           
           
           
           ; turn off all the segments
           clr.b  &SEG_PORT                     
           
ReadPort1 ; will test for single button press but not combinations of buttons
            ; note buttons are in positions: 10BB1BB0
           ;The following comments are in the form (Button 1-4)
Part1           
          ;(Bit 1)
           ;(HLLL)
           cmp.b # 0BCh, &P1IN    
           jne   Part2
           jeq
Part2      cmp.b # 0BAh, &P1IN
           jne  Case_ONE
           cmp.b # 0AEh, &P1IN
           jne   Case_THREE
           cmp.b # 09Eh, &P1IN
          
           ;(LHLL)                       
          ; cmp.b # 0BAh, &P1IN    
           ;jeq   Case_TWO
           ;;(HHLL)
           
           ;jeq  Case_THREE
           ;(LLHL)
          ; cmp.b # 0AEh, &P1IN
          ; jeq   Case_FOUR
           ;(LLLH)
           ;cmp.b # 09Eh, &P1IN
           ;jeq   Case_EIGHT                   

           ;(LLLL)
           ;jmp Case_ZERO  ; no match  (no single button is pressed at this time)




;Cases to make letters  and numbers
;-------------------------------------------------------------------------------
Case_ZERO         
           
           mov.b #ZERO, &SEG_PORT
           jmp Done           


Case_ONE          
           
           mov.b #ONE, &SEG_PORT
           jmp Done
           
Case_TWO          
           
           mov.b #TWO, &SEG_PORT
           jmp Done
          
Case_THREE mov.b #THREE, &SEG_PORT
           jmp Done
 
 
          
Case_FOUR
           mov.b #FOUR, &SEG_PORT
           jmp Done

Case_FIVE
           mov.b #FIVE, &SEG_PORT
           jmp Done
           
Case_SIX
           mov.b #SIX, &SEG_PORT
           jmp Done
           
Case_SEVEN
           mov.b #SEVEN, &SEG_PORT
           jmp Done

Case_EIGHT
           mov.b #EIGHT, &SEG_PORT
           jmp Done
           
Case_NINE
           mov.b #NINE, &SEG_PORT
           jmp Done
           
Case_A
           mov.b #Letter_A, &SEG_PORT
           jmp Done   

Case_B
           mov.b #Letter_B, &SEG_PORT
           jmp Done

Case_C     mov.b #Letter_C, &SEG_PORT
           jmp Done           

Case_D     mov.b #Letter_D, &SEG_PORT
           jmp Done
          
Case_E     mov.b #Letter_E, &SEG_PORT
           jmp Done

Case_F     mov.b #Letter_F, &SEG_PORT
           jmp Done
;-------------------------------------------------------------------------------     
           
Done:      call #Delay_Long

           ; turn off all the segments to clear results of last PB press
           clr.b  &SEG_PORT
           ; Go back to top
        
           jmp ReadPort1
      


;-------------------------------------------------------------------------------
;           End of main code
;-------------------------------------------------------------------------------                                            
                                           
;-------------------------------------------------------------------------------
;           Subroutines
;-------------------------------------------------------------------------------


;-------------------------------------------------------------------------------
; Delay_Long
;  passed in - nothing
;  returned - nothing
;  accomplishes - long delay
;  uses: R15
;-------------------------------------------------------------------------------
Delay_Long
    push R15     ; save R15 since we use it here
DelayTopL
    mov #LONG_DELAY, R15     ;load loop counter (R15) with Long Delay constant
Loop1Long
    dec R15                     ; decrement loop counter
    jnz Loop1Long               ; Zero yet?, no decrement again

    pop R15     ; restore R15 before returning
    ret         ; return
;-------------------------------------------------------------------------------
;  end of Delay_Long
;-------------------------------------------------------------------------------

;-------------------------------------------------------------------------------
;           End of all Subroutines
;-------------------------------------------------------------------------------

;-------------------------------------------------------------------------------
;           Interrupt Vectors
;-------------------------------------------------------------------------------

            ORG     0FFFEh                  ; MSP430 RESET Vector
            DW      RESET                   ; establishes the label RESET as
                                            ; the starting point
            END                             ; END of all code for this program
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
 

Link to post
Share on other sites

Several comments: First, before someone gets in an uproar, please put code into a code block for easy reading. THis is the <> button in the control bar. Makes it MUCH easier to read. You might also want to go to the new users section and introduce yourself.

 

 

As to your project: several ways to go that don't require a lot of extra code

 

a) use two inputs. One to count, the second to load. Kind of like setting a digital clock. to load 0110, press the count six times, then press load

 

b  have each of the four bit inputs toggle the bit in question. Press the 2^2 button, and bit 2 changes state. A seperate  load button again completes the operation

 

c) use switches instead of buttons to set the input. Again, a load button to complete the process

 

d) Use a load button to latch the input state directly.

 

Note the trend here. A load button is the easiest way to go. Minimal change to what you have. Just watch the single input bit tied to it and Robert is your mothers brother.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...