[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

8051 Assembly Language Problem

Posted on 2006-04-11
7
Medium Priority
?
1,685 Views
Last Modified: 2008-01-09
I have a problem. i am trying to create assembly code that reads from a keypad button and sends the value to the display, the buttons are 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f


the segment codes are as follows, KCODE0: db 3Fh,06h,5Bh,4Fh KCODE1: db 66h,6Dh,7Dh,07h KCODE2: db 7Fh,67h,77H,7Ch KCODE3: db 58h,5Eh,79h,71h

each KCODE relates to a certain coloumn.

My program is meant to display a character say a, when the button a is pressed, and it is meant to stay solid, as in constantly on, until another button is pressed, say b. b then replaces the register of where A resided, and A is shifted to the next register..


The registers available are, R0, R1, R2, R3, this correspoind to the registers, so say R3, would mean this value should show in the most right display. R4, and R5 are used to temporary store values so that they can be compared when buttons are pressed..

My problem that i am having is that when a button is pushed, the register displays the character straight away in the second seven segment display, and the first seven segment display only shows an output when the button is pressed, therefor when the button is depressed, the first seven segment display character disappears and the second seven segment display, the character stays solid..

How would you get it to display two different characters when one button is pushed and when another one is, the register shifts the values...


Hope that explains my problem, Points mostly awarded for helping by providing examples of code:-)

Any questions please ask
0
Comment
Question by:deepanp
  • 3
  • 3
7 Comments
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 16432549
Hi deepanp,

Could you post some code to help us understand?

Paul
0
 

Author Comment

by:deepanp
ID: 16434613
Hey Paul, sorry i was meant to do that:)


Here it is...


=====

;=======================================================
;Coursework for ELE475: ee05a002.asm
;created : 16th March 2006 by Yvonne Querner
;=======================================================

#include <pcx51.inc>
#include <Rc51Regs.inc>

RDpin equ 0xB3       ;address of RD pin
WRpin equ 0xB2
A0pin equ 0xB5
A1pin equ 0xB4

;=======================================================
; 8051 hardware vectors
;=======================================================
org 00h ; power up and reset vector
ljmp start
org 03h ; interrupt 0 vector (external hardware interrupt 0)
ljmp start
org 0bh ; timer 0 interrupt vector
ljmp start
org 13h ; interrupt 1 vector (external hardware interrupt 1)
ljmp start
org 1bh ; timer 1 interrupt vector
ljmp start
org 23h ; serial port interrupt vector
ljmp start

;----the wake-up program
org 100h

KCODE0: db 3Fh,06h,5Bh,4Fh
KCODE1: db 66h,6Dh,7Dh,07h
KCODE2: db 7Fh,67h,77H,7Ch
KCODE3: db 58h,5Eh,79h,71h

org 200h

start:
; set WRpin'and RDpin' high (off) -RD,WR active low
setb RDpin ; read signal
setb WRpin ; write signal

; set address to control register
setb A0pin
setb A1pin
; set control word
mov a,#81h ;81h control word for the input/output
mov P1,a
; send write pulse to 8255
lcall write

; set word to 0
mov a,#00h
mov P1,a

; set port to write to (A)
clr A0pin
clr A1pin
; send write pulse to 8255
lcall write

; set port to B
setb A0pin
clr A1pin
; send write pulse to 8255
lcall write

; set port to C
clr A0pin
setb A1pin
; send write pulse to 8255
lcall write

; clear registers (just to be on safe side)
mov R0,#00h
mov R1,#00h
mov R2,#00h
mov R3,#00h
mov R4,#00h
mov R5,#00h


;------- Start Keypad Loop ---------
KLoop:
      clr A0pin
      setb A1pin      ;select port C
    lcall write

AGAIN:      ;Test to see if keypad pressed
      mov a,#11110000b;send 1111b to upper nibble of Port C
      mov P1,a
      lcall write      ;send write impuls to 8255

      mov a,#FFh      ;a=FF hex
      mov P1,a      ;make P1 an input port
                  ;by writing all 1s to it
;    lcall write
    lcall read      ;send read impulse to 8255
      
;      mov a,P1      ;get data from P1
      mov R4,a      ;store data in R4
      mov a,#0Fh      ;a=0F hex
      ANL a,R4      ;a=a AND R4
      JZ AGAIN      ;jump if a=0

;Establish which key has been pressed
;ROW0
      mov a,#00010000b;test row0      
      mov P1,a
      lcall write      ;send write impuls to 8255
      
      mov a,#FFh      ;a=FF hex
      mov P1,a      ;make P1 an input port
                  ;by writing all 1s to it
;    lcall write
      lcall read      ;send read impulse to 8255

;      mov a,P1      ;get data from P1
      mov R5,a      ;store data in R5
      mov a,#0Fh      ;a=0F hex
      ANL a,R5      ;a=a AND R5
      JZ  ROW1      ;jump if a = 0

      ;test which key in row0 was pressed
      mov a,#00000001b;test key 0
      ANL a,R4      ;a = a AND R4
      JNZ BET0
      ;if a is not 0 key0 was pressed

      mov a,#00000010b;test key 1
      ANL a,R4      ;a = a AND R4
      JNZ BET1      ;if a is not 0 key1 was pressed      

      mov a,#00000100b;test key 2
      ANL a,R4      ;a = a AND R4
      JNZ BET2      ;if a is not 0 key2 was pressed

      mov a,#00001000b;test key 3
      ANL a,R4      ;a = a AND R4
      JNZ BET3      ;if a is not 0 key3 was pressed

BET0:   LJMP KEY0
BET1:   LJMP KEY1
BET2:   LJMP KEY2
BET3:   LJMP KEY3


ROW1:      mov a,#00100000b;test row1      
      mov P1,a
      lcall write      ;send write impuls to 8255
      
      mov a,#FFh      ;a=FF hex
      mov P1,a      ;make P1 an input port
                  ;by writing all 1s to it
;    lcall write
    lcall read      ;send read impulse to 8255
      
;      mov a,P1      ;get data from P1
      mov R5,a      ;store data in R5
      mov a,#0Fh      ;a=0F hex
      ANL a,R5      ;a=a AND R5
      JZ  ROW2      ;jump if a = 0

      ;test which key in row1 was pressed
      mov a,#00000001b;test key 4
      ANL a,R4      ;a = a AND R4
      JNZ BET4      ;if a is not 0 key4 was pressed

      mov a,#00000010b;test key 5
      ANL a,R4      ;a = a AND R4
      JNZ BET5      ;if a is not 0 key5 was pressed      

      mov a,#00000100b;test key 6
      ANL a,R4      ;a = a AND R4
      JNZ BET6      ;if a is not 0 key6 was pressed

      mov a,#00001000b;test key 7
      ANL a,R4      ;a = a AND R4
      JNZ BET7      ;if a is not 0 key7 was pressed

BET4:   LJMP KEY4
BET5:   LJMP KEY5
BET6:   LJMP KEY6
BET7:   LJMP KEY7


ROW2:      mov a,#01000000b;test row2      
      mov P1,a
      lcall write      ;send write impuls to 8255
      
      mov a,#FFh      ;a=FF hex
      mov P1,a      ;make P1 an input port
                  ;by writing all 1s to it
;    lcall write
    lcall read      ;send read impulse to 8255
      
;      mov a,P1      ;get data from P1
      mov R5,a      ;store data in R5
      mov a,#0Fh      ;a=0F hex
      ANL a,R5      ;a=a AND R5
      JZ  ROW3      ;jump if a = 0

      ;test which key in row2 was pressed
      mov a,#00000001b;test key 8
      ANL a,R4      ;a = a AND R4
      JNZ KEY8      ;if a is not 0 key8 was pressed

      mov a,#00000010b;test key 9
      ANL a,R4      ;a = a AND R4
      JNZ KEY9      ;if a is not 0 key9 was pressed      

      mov a,#00000100b;test key A
      ANL a,R4      ;a = a AND R4
      JNZ KEYA      ;if a is not 0 keyA was pressed

      mov a,#00001000b;test key b
      ANL a,R4      ;a = a AND R4
      JNZ KEYb      ;if a is not 0 keyb was pressed

ROW3:      mov a,#10000000b;test row3      
      mov P1,a
      lcall write      ;send write impuls to 8255
      
      mov a,#FFh      ;a=FF hex
      mov P1,a      ;make P1 an input port
                  ;by writing all 1s to it
;    lcall write
    lcall read      ;send read impulse to 8255

;      mov a,P1      ;get data from P1
      mov R5,a      ;store data in R5
      mov a,#0Fh      ;a=0F hex
      ANL a,R5      ;a=a AND R5
      JZ  AGAIN1      ;jump if a = 0

AGAIN1: ;LJMP AGAIN

      ;test which key in row1 was pressed
      mov a,#00000001b;test key c
      ANL a,R4      ;a = a AND R4
      JNZ KEYc      ;if a is not 0 keyc was pressed

      mov a,#00000010b;test key d
      ANL a,R4      ;a = a AND R4
      JNZ KEYd      ;if a is not 0 keyd was pressed      

      mov a,#00000100b;test key e
      ANL a,R4      ;a = a AND R4
      JNZ KEYe      ;if a is not 0 keye was pressed

      mov a,#00001000b;test key F
      ANL a,R4      ;a = a AND R4
      JNZ KEYF      ;if a is not 0 keyF was pressed



KEY0:   mov R4,#00111111b ;load segment value to R4
      LJMP NEXT
KEY1:      mov R4,#00000110b ;load segment value to R4
      LJMP NEXT
KEY2:      mov R4,#01011011b ;load segment value to R4
      LJMP NEXT
KEY3:      mov R4,#01001111b ;load segment value to R4
      LJMP NEXT
KEY4:      mov R4,#01100110b ;load segment value to R4
      LJMP NEXT
KEY5:      mov R4,#01101101b ;load segment value to R4
      LJMP NEXT
KEY6:      mov R4,#01111101b ;load segment value to R4
      LJMP NEXT
KEY7:      mov R4,#00000111b ;load segment value to R4
      LJMP NEXT
KEY8:      mov R4,#01111111b ;load segment value to R4
      LJMP NEXT
KEY9:      mov R4,#01101111b ;load segment value to R4
      LJMP NEXT
KEYA:      mov R4,#01110111b ;load segment value to R4
         LJMP NEXT
KEYb:      mov R4,#01111100b ;load segment value to R4
      LJMP NEXT
KEYc:      mov R4,#01011000b ;load segment value to R4
      LJMP NEXT
KEYd:      mov R4,#01011110b ;load segment value to R4
      LJMP NEXT
KEYe:      mov R4,#01111001b ;load segment value to R4
      LJMP NEXT
KEYF:      mov R4,#01110001b ;load segment value to R4
      LJMP NEXT
      
;The segment value of the key pressed must
;be loaded into R0 once R1 is assigned the
;previous value of R0, R2 is assigned the
;previous value of R1 and R3 is assigned the
;previous value of R2.

NEXT:

    mov a, R0
    mov R1, a

    mov a, R1
    mov R2, a

    mov a, R2
    mov R3, a

    mov a,R4
    mov R0,a

   
    acall display


   
;;;;;;;;;;;;;;;;;;;
    ;mov a, R2
;      mov R3, a

    ;mov a, R1
    ;mov R2, a

   ; mov a, R0
    ;mov R1, a

    ;mov a, R4
    ;mov R0,a
;;;;;;;;;;;;;;;;;;;

;working flashing
   
;;;;;;;;;;;;;;;;

    ;mov a, R0

    ;mov R1,a
   ; mov a,R1
   
    ;mov R2,a
   ; mov a,R2

    ;emov R3,a
   
   
   
    ;R3 is assigned the previous value of R2
      ;mov a,R1
      ;ov R2,a      ;R2 is assigned the previous value of R1
      ;mov a,R0
      ;mov R1,a      ;R1 is assigned the previous value of R0
      ;mov a,R4
      ;mov R0,a      ;value in R4 is loaded into R0

;Refresh to the display


ljmp KLoop ;return to start of loop

;------- End Keypad Loop ---------



;----- Start Display Subroutine -------
display:
      mov a,R0 ; load acc with first character
      mov P1,a
      clr A0pin
      clr A1pin ; select Port A
      acall write ; write character from acc to P1

      mov a,#00000001b
      mov P1,a
      clr A1pin
      setb A0pin ; select Port B
      acall write ; enable first display module
      lcall delay  
   
    ;;;;;;;;;;;;;;;;;;;;;


   
    mov a, R1
    mov P1, a
    clr A0pin
    clr A1pin
    acall write

    ;;;; send to the second display thing
   mov a, #00000010b
    mov P1, a
    clr A1pin
    setb A0pin
  acall write
    lcall delay

    mov a, R2
    mov P1, a
    clr A0pin
    clr A1pin
    acall write

    mov a, #00000100b
    mov P1, a
    clr A1pin
    setb A0pin
    acall write
    lcall delay

mov a, R3
    mov P1, a
    clr A0pin
    clr A1pin
    acall write
   
    mov a, #00001000b
    mov P1, a
    clr A1pin
    setb A0pin
    acall write
    lcall delay

     

;mov a, #00h
 ;   mov P1, a
  ;  acall write


    ;;;;;;;;;;;;;;;;;;;;;
   
   

      
      ret
;----- End Display Subroutine -------


;----- Start WRITE Subroutine -------
write:
      clr WRpin
      nop
      setb WRpin
      nop
      ret
;----- End WRITE Subroutine -------


;----- Start READ Subroutine -------
read:
      clr RDpin
    nop
      mov a,P1      ;get data from P1
      nop
      setb RDpin
      nop
      nop
      nop
      ret
;----- End READ Subroutine -------


;---- Start DELAY Subroutine ------
delay:
      mov a, #0ffh ; delay a bit for...
dly:
      djnz acc, dly ; ...for debouncing

      ret
end
;------ End DELAY Subroutine ------      
0
 
LVL 3

Expert Comment

by:PeterdLo
ID: 16439941
Hi deepanp,

By briefly examing your code, I discovered your NEXT: logic should be coded as follows.

NEXT:
    mov a, R2
    mov R3, a
   
    mov a, R1
    mov R2, a
   
    mov a, R0
    mov R1, a

    mov a,R4
    mov R0,a

Try it,  let me know if you still have a problem. Good luck.
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 

Author Comment

by:deepanp
ID: 16444341
it still doesn't work, the code should have some kind of delay that is needed, in order for the display to display character by character, other then instantly switching characters..
0
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 1000 total points
ID: 16538813
Hi deepanp,

Sorry nobody got back to you. I was hoping PeterLo would continue helping. Perhaps he is busy doing something else.

There are many ways of achieving delays. It depends in what environment you are running.

The easiest is to perform a loop counting down from a large number to zero. If this is not long enough, make another loop that calls this one, counting down again. This mechanism is only acceptable when you are the only process running on the CPU because you will lock up the system during your loops.

Other techniques will rely on calling operating system functions in the loop to allow it to make use of the time you wish to waste. Do you need to do this?

Paul

P.S. If you need extra help on any page at EE, especially if you think your question is being overlooked for some reason, the easiest way to get it is to e-mail the Page Editor of the page on 'their name' 'at' experts-exchange.com. I wont put mine here in clear text as e-e pages are crawled by quite a lot of bots but I am sure you can work it out. The name of the page editor is on the left of your screen under the picture (yes! thats me! :-)
0
 

Author Comment

by:deepanp
ID: 16556667
Hey PAUL, I'm So Sorry for the late delay of replying to the message, but i will be having exams coming in about a weeks time, so i have been concentrating on that, and i have given up on this task and did what i could, due to the time left.. Cheers for getting back to me, i thought that you were busy in fact :) and the page didn't seem to be going anywhere with the question so i kind of forgot to close the session down. Umm to be honest, i am not sure how to refund the points back, but as it is that you have given some advice here goes..

:)..

Hope to hear from your great expert-advice next time i am in need..

Thanks again

Deepan
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 16556791
Hi Deepan,

Thanks! Come back soon :-)

Paul
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month20 days, 7 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question