Last night I decided to get round to buying two cables, a 3-pin and a 5-pin female PCB socket connector, along with one 3-pin male connector. I could have got the cables as a length of wire, and a few end pieces but I was feeling a bit lazy. Two wires should be plenty for testing the DMX lights I'm going to buy in a bit, (the local theatre is buying some cheap LED parcans for the next show so I've said I'll buy two back after the show so they can reduce the budget and so I can get two lights to play with).. The LED pars have 3-pin DMX connectors, hence the 3-pin stuff. The 5-pin is because I believe that is the proper DMX connector. 2 wires to plug DMX from the circuit to one light, then the second for the wire between the two lights.
The company phoned this morning saying they didn't have 2meter cables in black, so I changed it to a red and a blue ire instead. I'd have preferred black, but when it comes to it they are only really meant for testing.
Anyway I'm off for an extended weekend, hence the day off work. I've been thinking about my problem setting the PortB bits on the circuit and programming in the LED segment. While I may be in a bit of a rush, I thought Meh, and sat down for an hour...
A little searching on the Microchip site shows that I should be setting the "LATB" register when I'm using the bsf and bcf methods to stop any inputs interferring or something... Changing that and it solved all my previous problems trying to set those LED segments, (wierd how something so simple wastes so much time).
Anyway I've now coded a few macro's based on how I've wired the chip at the moment so I can use the Macro's to set the LED segment to match a certain entry. It's a shame I couldn't use one full 8-bit port really as that would have meant just two processor instructions to set the segment. As it is, I need four, (and thinking about it maybe I should be using LATC instead of PORTC when setting it to a byte, however for now the macro's for the segment settings is shown below:
SET_PORTC MACRO PortCValue
MOVLW PortCValue
MOVWF PORTC
ENDM
SET_SEGMENT_TO_0 MACRO
SET_PORTC 0x80
bcf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_1 MACRO
SET_PORTC 0xFB
bcf LATB, 0
bsf LATB, 1
ENDM
SET_SEGMENT_TO_2 MACRO
SET_PORTC 0x44
bcf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_3 MACRO
SET_PORTC 0x41
bcf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_4 MACRO
SET_PORTC 0x03
bcf LATB, 0
bsf LATB, 1
ENDM
SET_SEGMENT_TO_5 MACRO
SET_PORTC 0x01
bsf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_6 MACRO
SET_PORTC 0x00
bsf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_7 MACRO
SET_PORTC 0xFB
bcf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_8 MACRO
SET_PORTC 0x00
bcf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_9 MACRO
SET_PORTC 0x01
bcf LATB, 0
bcf LATB, 1
ENDM
SET_SEGMENT_TO_CLEAR MACRO
SET_PORTC 0xFF
bsf LATB, 0
bsf LATB, 1
ENDMI then wrote a little counter program to cycle through each of the numbers and blank entries listed above:
Start_Num_Loop
SET_SEGMENT_TO_CLEAR
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_0
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_1
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_2
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_3
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_4
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_5
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_6
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_7
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_8
call Delay ; Call the Delay procedure to wait a bit
SET_SEGMENT_TO_9
call Delay ; Call the Delay procedure to wait a bit
Anyway that will do for now, no time to make it show A-F, and to use a slider as an input... Next time!
No comments:
Post a Comment