Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LED Scrolling Message Code in 'C'

Status
Not open for further replies.

Bronx68

New Member
I have written code in PIC assembly to perform this task but would like to see some basic example of 'C' code to perform this task.
 
The code to do that would vary wildly based on how the LEDs are connected, driven, how big the display is, font size, direction of scroll, etc. Perhaps show your implementation and setup then see if others care to comment.
 
LTX71CM,
1) The led matrix is 7 rows with 20 columns
The 7 rows are connected to the output of the PIC processor
The 20 columns are connected to a counter that is clocked by the PIC
2) A this point the scroll direction is not important
Here is the debugged assembly code. I need some help getting with writing the C equivalent of this code
__CONFIG _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _MCLR_ON & _WDT_OFF & _INTRC_IO ; _HS_OSC ; _INTRC_IO
; ******************Defined Variables*********************************************************
#define Row1 PORTB,0 ; Row 1
#define Row2 PORTB,1 ; Row 2
#define Row3 PORTB,2 ; Row 3
#define Reset4017 PORTA,4 ; Reset counters
#define Clk4017 PORTA,3 ; Clock counters

;*********************************************************************************************

; **********Variables*************************************************************************
CBLOCK 0x21
Ghost1 ; Ghost register 1
Ghost2 ; Ghost register 2
Ghost3 ; Ghost register 3
Ghost4 ; Ghost register 4
Ghost5 ; Ghost register 5
Ghost6 ; Ghost 6
Ghost7 ; Ghost 7
Ghost8 ; Ghost 8
Ghost9 ; Ghost 9
Ghost10 ; Ghost 10
Ghost11 ; Ghost 11
Ghost12 ; Ghost 12
Ghost13 ; Ghost 13
Ghost14 ; Ghost 14
Ghost15 ; Ghost 15
Ghost16 ; Ghost 16
Ghost17 ; Ghost 17
Ghost18 ; Ghost 18
Ghost19 ; Ghost 19
Ghost20 ; Ghost 20
Index ; Jump value for table
Scancount ; Count the number of scans of the display
Delaycol ; Delay for viewing the column
Delaycol2 ; Additional column delay for viewing
ENDC
;*********************************************************************************************

;***** VARIABLE DEFINITIONS*******************************************************************
w_temp EQU 0x7E ; variable used for context saving
status_temp EQU 0x7F ; variable used for context saving
;*********************************************************************************************

; Main Code routine
org 0x000 ; Main code routine
goto Main

;*****************************************************************
;**************************


;****************************************************************
;**************************

Main:
; INTOSC with 8MHz clock frequency if config is _INTRC_IO

banksel OSCCON
movlw b'01110100' ; to set oscillator control registor for 8 Mhz (8Mhz source drives clk directly)
;0------- Not used
;-100---- Set clock to 8 Mhz source drives clock directly
;----0--- Unimplemented
;-----1-- Frequency is stable bit
;------00 Unimplemented
movwf OSCCON




; banksel OPTION_REG ; Select the RAM bank 1
banksel TRISB

;****************PORTB has all outputs and PORTA has inputs and outputs************************************


movlw 0x00 ; Select PORTB as outputs
movwf TRISB


movlw b'11000111' ; Set porta inputs and outputs

movwf TRISA
banksel PORTA ; Select RAM bank0


clrf PORTA ;Initialize I/O port as outputs
bsf PORTA,2
nop
Goto Run1


;Table1

Table1 ADDWF PCL,1 ;Add W to Program Counter was ADDWF 02h,1
RETLW 00h
RETLW 3Fh ;A
RETLW 48h
RETLW 48h
RETLW 48h
RETLW 3Fh
RETLW 00h
RETLW 7Fh ;R
RETLW 48h
RETLW 4Ch
RETLW 4Ah
RETLW 31h
RETLW 00h
RETLW 40h ;T
RETLW 40h
RETLW 7Fh
RETLW 40h
RETLW 40h
RETLW 00h
RETLW 0FFh

Run1 clrf Ghost1 ;Clear the Ghost locations
clrf Ghost2
clrf Ghost3
clrf Ghost4
clrf Ghost5
clrf Ghost6
clrf Ghost7
clrf Ghost8
clrf Ghost9
clrf Ghost10
clrf Ghost11
clrf Ghost12
clrf Ghost13
clrf Ghost14
clrf Ghost15
clrf Ghost16
clrf Ghost17
clrf Ghost18
clrf Ghost19
clrf Ghost20
MOVLW 00 ;move 0 to W
MOVWF Index ;is the jump value for table
Run2 MOVLW 20h ;was 40h but 20h speeds up the display
MOVWF Scancount ;counts the number of scans was
CALL Shift ;and controls the "run speed"
INCF Index,1 ;increment the table index
MOVF Index,0 ;Put jump value into W
CALL Table1
MOVWF Ghost20 ;W contains table data
XORLW 0FFh ;If table value is FF all done,
BTFSC STATUS,2 ; bit 2 of status reg will be SET (=1)
GOTO Run1 ;Start Table1 data again
Run3 DECFSZ Scancount,1 ;Scan the display 20h times was to 40h times
GOTO Run4
GOTO Run2
Run4 CALL Scan
GOTO Run3



Scan BSF Reset4017 ;Reset 4017 counter
NOP
NOP
NOP
NOP
NOP
NOP
BCF Reset4017


CALL DelD ;Sets up first column high
MOVF Ghost1,0 ;Output the data from the 20 Ghost
MOVWF PORTB ; locations to the display
CALL DelD
MOVF Ghost2,0
MOVWF PORTB ;
CALL DelD
MOVF Ghost3,0
MOVWF PORTB
CALL DelD
MOVF Ghost4,0
MOVWF PORTB
CALL DelD
MOVF Ghost5,0
MOVWF PORTB
CALL DelD
MOVF Ghost6,0 ;Output the data from reg .
MOVWF PORTB ; locations to the display
CALL DelD
MOVF Ghost7,0
MOVWF PORTB ;
CALL DelD
MOVF Ghost8,0
MOVWF PORTB
CALL DelD
MOVF Ghost9,0
MOVWF PORTB
CALL DelD
MOVF Ghost10,0
MOVWF PORTB
CALL DelD

MOVF Ghost11,0 ;Output the data from
MOVWF PORTB ; locations to the display
CALL DelD
MOVF Ghost12,0
MOVWF PORTB ;was MOVWF 06h need to
CALL DelD
MOVF Ghost13,0
MOVWF PORTB
CALL DelD
MOVF Ghost14,0
MOVWF PORTB
CALL DelD
MOVF Ghost15,0
MOVWF PORTB
CALL DelD
MOVF Ghost16,0 ;Output the data from the
MOVWF PORTB ; locations to the display
CALL DelD
MOVF Ghost17,0
MOVWF PORTB ;
CALL DelD
MOVF Ghost18,0
MOVWF PORTB
CALL DelD
MOVF Ghost19,0
MOVWF PORTB
CALL DelD
MOVF Ghost20,0
MOVWF PORTB
CALL DelD ;f this commented out co
CALL Lastcoldelay ;additional delay to keep column 20 on longer

RETURN

Shift movf Ghost2,w ;move the data from ghost 2 to ghost 1
movwf Ghost1 ;
movf Ghost3,w ;move the data from ghost 3 to ghost 2
movwf Ghost2 ;
movf Ghost4,w ;move the data from ghost 4 to ghost 3
movwf Ghost3 ;
movf Ghost5,w ;move the data from ghost 5 to ghost 4
movwf Ghost4 ;
movf Ghost6,w ;move the data from ghost 6 to ghost 5
movwf Ghost5 ;
movf Ghost7,w ;move the data from ghost 7 to ghost 6
movwf Ghost6 ;
movf Ghost8,w ;move the data from ghost 8 to ghost 7
movwf Ghost7 ;
movf Ghost9,w ;move the data from ghost 9 to ghost 8
movwf Ghost8 ;
movf Ghost10,w ;move the data from ghost
movwf Ghost9 ;
movf Ghost11,w ;move the data f ghost 11 to ghost 10
movwf Ghost10 ;
movf Ghost12,w ;move the data ghost 12 to ghost 11
movwf Ghost11 ;
movf Ghost13,w ;move the data ghost 13 to ghost 12
movwf Ghost12 ;
movf Ghost14,w ;move the data from 14 to ghost 13
movwf Ghost13 ;
movf Ghost15,w ;move the data from 15 to ghost 14
movwf Ghost14 ;
movf Ghost16,w ;move the data ghost 16 to ghost 15
movwf Ghost15 ;
movf Ghost17,w ;move the data ghost 17 to ghost 16
movwf Ghost16 ;
movf Ghost18,w ;move the data ghost 18 to ghost 17
movwf Ghost17
movf Ghost19,w ;move the data ghost 19 to ghost 18
movwf Ghost18 ;
movf Ghost20,w ;move the data ghost 20 to ghost 19
movwf Ghost19
RETURN

DelD
DECFSZ Delaycol,1 ;Delay for viewing the
; DECFSZ Delaycol2,1 ;Delay for viewing the
; DECFSZ Delaycol,1 ;Delay for viewing the not sure if help brightness
GOTO DelD ;column of LEDs
MOVLW 00h
MOVWF PORTB ;was movwf 06
NOP ;removes trailing ghosting
NOP
Clk BSF Clk4017 ;Clock the 4017 which switches on next column
NOP ; the next output
NOP
BCF Clk4017
RETURN

Lastcoldelay DECFSZ Delaycol,1 ;Delay for displaying last column
GOTO Lastcoldelay
Clklast BSF Clk4017
NOP
NOP
BCF Clk4017
return

END
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top