Light Rotation on 7 Segment LED

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 ....
XORLW 0x60
BNZ _00108_DS_
MOVLW 0x03
; 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 ...
BRA _00113_DS_
MOVLW 0x3f

It is just about 5 line of code as usual.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s