Tags

,

In one of my PIC lab, I asked the students tried to circulate the lights (of two lines) on 7 segment LED. That is, A-B, B-C, …. F-G, G-A, and A-B again. However, I found it looked ugly and I asked them to make the circulation without going through the segment G.

Rotation of lights from AB to BC, …., EF and FA (without go through G).

If I were to write this in C programming, it will be something like these:
//...
// Somewhere after "rlnc PORTD" -- the rotation of 7 segments lines.
// ...
if (PORTD == 0b01100000){
PORTD = 0b00000011;
}
// ...

That is, if it was the lines of G-A, then change it to A-B.

Many of them (OK … excluding the Robot students..) struck very hard to get this done.
If you have SDCC or any PIC C compiler, you can just type your C code and change it to assembly. These are what I got from my SDCC.

;
; Somewhere at the middle ....
;
MOVF _PORTD, W
XORLW 0x60
BNZ _00108_DS_
MOVLW 0x03
MOVWF _PORTD
_00108_DS_:
;
; Continue to somewhere
;

Surprisingly it was just a simple XOR operation of 5 lines codes.

#
p/s: PiKLab and SDCC are a good combination for C programming in Linux ^^.

# —- More Accurate Version —-
The more accurate flow is piping the PORT D bit 7 to bit 0 and the C code is something like this:
//
// Somewhere ...
//
if (PORTD & 0b01000000){// new test
PORTD = PORTD & 0b00111111;
PORTD = PORTD | 0b00000001;
}

And the assembly code is something like these:
;
; Somewhere ...
;
_00109_DS_:
BTFSS PORTD, 6
BRA _00113_DS_
MOVLW 0x3f
ANDWF PORTD, F
BSF PORTD, 0
_00113_DS_:

It is just about 5 line of code as usual.