Send input from PORTC to D (SW4-DIP, switches / 8*8 LED)

Thread Starter

pStrafe

Joined Jan 24, 2018
10
Alright, so I've been currently into assembly and learning about PICs.
I have bought a HL-K18 board with PIC18F4520 on it, there is also a 8*8 led matris and 4 pin switch.

My goal is to turn on one led in the first column. which I've done.
And then through the switches, if switch 1 is on the led(dot) should move up one bit, if the switch 4 is on the dot(led) should move down in the column one bit at the time.

Also if both switches are off the dot should remain at it's position, and if the dot is at the top and you have switch 1 on, it should just stay at the top. and vice verse if it's at the bottom.
Here's my code
Code:
MAIN    CLRF    TRISD ; Set portd as output
    BCF    TRISA,RA1; Set porta, column 1 as ouput
    BSF    PORTA,RA1; set porta to 0
    BSF    TRISB,RB0; input Don't know if rb0 is for switch 1
    BSF    TRISB,RB5; input Don't know if rb5 is for switch 4

LOOP
    MOVF    PORTB,W
    NOP ; No Operation so it can read the portb before sending to portd
    MOVLW    0x04  ; Have the first dot at 0x04.
    MOVWF    PORTD
  
    GOTO    LOOP
    end
Like I need some help with sending input from switch1 or 4 to portd
and then (shift?) the 0x04 to the right or left depending on what switch is on.

I've attached the Hl-k18 board
I have circled the switch schematic and the led.

View attachment HL-K18原理图.pdf
 

Attachments

absf

Joined Dec 29, 2010
1,952
Your program inside "LOOP" is too simple. It would not do what you wanted. The LED would remain in position 04 and it would light very very quickly and it appears as permanently lite for our eyes.

You have to expand the program in more details. 1. After reading the DIP switch from Port B, you have to determine which switch was ON and shift the LED accordingly. 2. you need to put some delays to slow down the LED e.g. 0.5 second would be fine.

I didn't simulate your schematic as I am busy painting my house now.;)

Allen
 
Top