Jump to content
 

Train Describes using 4 digit 7 segment displays?


St. Simon
 Share

Recommended Posts

  • RMweb Gold

Hi Kev,

 

Im assuming that the light blue and thick dark blue lines on the above diagram are 'thick' connections for the PCB?  In which case I have two things that I don't understand.  Firstly why the resisters are there (R7-R23) and what purpose they are serving?  From what I can see (and I'm obviously missing something) you have marked each one as corresponding to a specific pin on the displays, but they all appear to connect to the same track linking the resistors and Darlington Driver to the displays?  Hence how can they relate to a specific pin?

 

 

Rich

 

As has been previously answered, the "bus" lines are just a way of making circuit diagrams easier to "read" to electronics engineers.

(..but this only works if you know that is what they are AND you look at the circuit diagram as a complete entity. Just look at the uC circuit - every pin is connected to it!)

 

Bus lines were originally used for the Data and Address buses of uProcessor based circuits.

Nobody now would draw each data line, of a 64 bit based PC motherboard, separately!

 

 

Kev.

Link to post
Share on other sites

  • RMweb Gold

Afternoon all,

 

Hi Rich,

 

I'm confused as to what display you are looking at. The data sheet you link to is for a 5 by 7 dot matrix display, not the segment alpha numeric display in the circuit diagram before. Are you re-designing Kev's complete circuit? There is listed on the data sheets working values for current/voltage and maximum values, too. You select the resistance value to limit the current through the LED to be less than the maximum. The actual value of the resistor will depend on the voltage and the pulse rate duty cycle. For long life, use the highest value resistor that allows the led to be clearly illuminated, not a low value that allows the LED to be as bright as possible.

 

So, if you're applying 3V, and the limit is 30mA, then the resistor will be in the region of 100ohm, but I'd try a 1k, see if it was bright enough, then work towards 100ohm. .

 

Sorry to have confused you - I easily confuse myself!!  Im looking at using the dot-matrix displays, but it was Kev's original plan that set me thinking. I've got a little background in electronics (perhaps basic minimum would be better!) but I'm looking to fully understand not only Kev's circuit, but the reasons behind the different components of it, before moving forward with my own.

 

Rich, in order to understand a diagram, it's important to learn about PCB design and how they're made in the first place. Although this deals with a specific program for making PCB's, the general workflow outlined in their docs is pretty common amongst all of them.

 

read up on: http://docs.kicad-pcb.org/stable/en/getting_started_in_kicad.html

 

 

Thanks for the link. I've been doing quite a bit of reading up on PCB design, but on looking/reading that the penny didn't drop until after I looked at the PCB circuits!  I'll go have a read of the link however.

 

Rich

Link to post
Share on other sites

  • RMweb Gold

Hi Rich, there are good answers above but, for the Darlington Driver, you are essentially correct - with a few provisos...

 

These Darlington Driver ICs come in 4 basic types - 8 or 7 Channel with/without Input Bias Resistors.

(Also in a variety of packages.)

 

Yes the ULN2803A has 8 channels. I use six to switch (one at a time) a 17-segment digit display on.

 

Kev.

 

Kev,

Thanks for the reply and the explanation, thats really helped. Thank you.

 

Am I right in thinking that you haven't posted the PIC code for your device?

 

Rich

Link to post
Share on other sites

  • RMweb Gold

Kev,

Thanks for the reply and the explanation, thats really helped. Thank you.

 

Am I right in thinking that you haven't posted the PIC code for your device?

 

Rich

 

Your welcome.

 

No, I haven't posted the code yet, but the code I do post will be teaching/thought provoking and not anything that can be run or cut-n-pasted into a form to suit you/anybody.

 

 

Kev.

Link to post
Share on other sites

  • RMweb Gold

Your welcome.

 

No, I haven't posted the code yet, but the code I do post will be teaching/thought provoking and not anything that can be run or cut-n-pasted into a form to suit you/anybody.

 

 

Kev.

 

 

Hi Kev,

Thats the best way!  I self-learnt PHP, Basic, VB and ASP.Net through examples that took you through some parts, and required you to create sections yourself, and knowing what your programming, how and why is the only way to learn.  I've had a good read of the code for the PICAXE, and 98% of it makes sense. Programming is the bit I really enjoy as I can get PCs and web pages to do whatever I want them to, the actual schematic and circuit design is the bit where I'm lacking, but want to learn as there's a few things I want to do with electronics for my new layout.

 

I'd also point out, just to avoid any suggestion that I was looking to cut-and-paste code (I wasn't), that the display I'm looking to use is a 5x7 dot-matrix grid and not a. 7 or 14-segment display as you have used, so any code couldn't be copied and pasted anyway.  I also need the displays (slaves) to listen to a master unit for what I'm looking to do, so equally, a copy and paste wouldn't work either!  Im just trying to get my head around the multiplexing side of code at the moment.  From what I can see (if I've understood correctly) your multiplexing one character between six displays, for mine, I'm multiplexing 35 LED dots on four displays, so certainly more complex from what I can see!!

 

Rich

Link to post
Share on other sites

Hi Rich,
 
A few years ago, I  did a fair bit with Microchip pics, For simplicity I homed in on using the PIC16f628(a these days) http://www.microchip.com/wwwproducts/en/PIC16F628A Initially programed in their assembler, then purchased an optimising  C compiler from ccs. (If I needed more than 16 io pins, I used more 16f628's) There is a stripped down c compiler for pics if you use the microchip ide. Although it may be a steep learning curve, I think you could enjoy the experience.
 
You can get dedicated chips to drive dot matrix displays, but it would be fun to write your own code using a 628 for each display, and sending the character values through their inbuilt usart's. Once you'd got one display working, simply repeat for however many you want, and a cheap usb tablet keyboard could input the characters to whatever bus system you want, to connect the various sets of displays together. If you decide to go that route, then a 100 off 16f628A's are about £1.50 each or less, and microchip often supply samples, if you qualify.
 
The Microchip PG164130 PICkit 3 Programmer at 50 quid will get you going, get a breadboard and maybe an old phone charger and away you go.

 

There will be plenty of pitfalls to keep you interested :no:

 

Best wishes,

 

Ray

Link to post
Share on other sites

  • RMweb Gold

Hi Ray,

You've pretty much hit the nail on the head there for 85% of what I'm thinking. I'll do a bit more research and reading up and report back!

 

Rich

Link to post
Share on other sites

Also, if you don't want to get into multiplexing, and only need a few alphabet characters, then a seven segment display is much simpler to use and cheaper, and provided there is no conflict with numbers, you can reasonably display upper case letters from A to J and L, P, S, U (and many of them and a few others in lower case).

Link to post
Share on other sites

If starting with PICs the '628 and the other 18-pin varieties are a bit old hat now. The 'low pin count' PICs are often easier to work with nowadays in sizes from 8-pin up to 20-pin and no need for a crystal most of the time.

Link to post
Share on other sites

  • RMweb Gold

Also, if you don't want to get into multiplexing, and only need a few alphabet characters, then a seven segment display is much simpler to use and cheaper, and provided there is no conflict with numbers, you can reasonably display upper case letters from A to J and L, P, S, U (and many of them and a few others in lower case).

  

 

Hi Ray,

Thanks. One of my problems (at times) is I try and get things too realistic! But in that spirit the dot matrix displays are more appropriate than segments, hence why I'm looking at them, plus I want to display 0-9, along with the characters A, E, M, N, O, S, T and Z on one or other of the displays, so I think for this purpose the dot-matrix will win! Thanks for the thought and comment tho.

 

If starting with PICs the '628 and the other 18-pin varieties are a bit old hat now. The 'low pin count' PICs are often easier to work with nowadays in sizes from 8-pin up to 20-pin and no need for a crystal most of the time.

 

 

Hi Suzie,

Thanks for saying in, always appreciate other peoples views, especially those more knowledgeable than me! I'm going to look for a PIC that can power the 5x7 dot matrix display, can multiplex and also has USART options, to allow it to receive the data to display from a master controller. I'll look at sorting the master controller out once I've got a couple of display modules built and working, as that will be more complicated, not only having to send the appropriate data to one of 20 odd displays, but also work out which display to send it to, and process data from a Loconet net feed. The simplest way of which may be to use a Loconet shield on a Ardunio, then send the necessary data over to the PIC master controller.

 

See I never set myself simple tasks!

 

 

The '628 doesn't need an external oscillator either. If a device fits the requirement and its price is acceptable, I see no need to look elsewhere just to be 'fashionable'.

Hi Gordon,

Thanks. Yes a very valid point. I'm a big believer in keeping it simple and using the best tool for the job, although I guess in this case, future compatibility needs to be looked at as well, if the newer chips are using a more updated programming instruction set or firmware, it may be beneficial to look at a more modern on. But I do agree, it's all about using what is actually needed.

 

It's just occurred to me, that I've hijacked somebody else's thread here, apologies to the thread originator that. I'll work on a circuit diagram, then start a new thread here for those that are interested, to follow the progress, comment and tell me how'if I could improve things!!

 

Rich

Link to post
Share on other sites

The '628 doesn't need an external oscillator either. If a device fits the requirement and its price is acceptable, I see no need to look elsewhere just to be 'fashionable'.

 

As much as I like to be thought of as fashionable, it is more about utility. The '628 is just the latest PIC to drop in to your existing 18-pin PIC project to give you a few more features - projects that might date back to the 16C84 when that was all you could get. If you want to use the '628 you will have to use an 18-pin PIC whether that is the sensible size for your project or not.

 

The advantage of the low pin count devices is that you can have code that with minor adjustments (or possibly no adjustment) can run in an 8-pin PIC, 14-pin PIC or 20-pin PIC depending on what you want to use it for. Twenty pins can be jolly handy for multiplexed display driving, while 8-pins can be handy for something you want small. Sometimes it can be handy to have a PIC with a 32MHz internal clock when you need a bit of processing power.

 

If you want to make use of an established code base, or modify existing projects then there are a few resources out there that you can tap in to if you use the '628 which make it attractive of course. It is not like the low pin count range of PICS is something new - the low pin count 12F629/16F630/16F631 have been around a long time just like the 16F628 (the numbers give you a clue!) but the latest ones in my toolbox (12F1840/16F1825/16F1829) are quite awesome in comparison so if you are starting out they are well worth looking at and just as easy to code as the '628 with the advantage that as new low pin count processors come along you can just drop in a better one like you can replace the good old 16F628A with a 16F1847 when you need that extra speed/peripheral/ram/eerom/flash (delete as appropriate).

 

When starting out you don't have the encumbrance of having to be backward compatible with existing projects - you can use the best tools available. I started using PICs some time ago and have always used the low pin count family - never needed to use an 18-pin device for a project! Low pin count is not as new as some people think.

Link to post
Share on other sites

  • 3 weeks later...
  • RMweb Gold

Before I post/explain the code for the multiplexed 17 segment display board AND1, I will post a quick project that fulfils the original requirement of this thread. This project can easily be expanded to display 'several' displays.

 

post-12815-0-80082300-1499020176_thumb.jpg

 

Program ACB1_HeadCode1

'Ver 1.0
'300617 - Initial Code
'010717 - Tidying up Code

 

' Hardware port I/O availability...
'Port A =
' GPA0 = AN0 = RA0
' GPA1 = AN1 = RA1
' GPA2 = AN2 = RA2
' GPA3 = AN3 = RA3
' GPA4 = AN4 = RA5
' GPA5 = AN5 = RE0
' GPA6 = AN6 = RE1
' GPA7 = AN7 = RE2

 

'Port B =
' GPB0 =     = RD0
' GPB1 =     = RD1
' GPB2 =     = RD2
' GPB3 =     = RD3
' GPB4 =     = RD4
' GPB5 = PGM = RB5
' GPB6 = PGC = RB6
' GPB7 = PGD = RB7

 

'Port C =
' GPC0 = AN11       = RB4
' GPC1 = AN9/CCP2   = RB3
' GPC2 = P1D        = RD7
' GPC3 = P1C        = RD6
' GPC4 = P1B        = RD5
' GPC5 = T1OSO/T13  = RC0
' GPC6 = P1A        = RC2
' GPC7 = T1OS1/CCP2 = RC1

 

' Variable declarations section...
Dim DisplayMessage as String[4]  ' Text string to be displayed 0-9,A-Z," -_='

' 4by7 Display Module pin definitions and directions...
Dim Chip_Select as sbit at RD0_bit               ' Display Select (Chip Enable)
Dim SoftSpi_CLK as sbit at RD3_bit               ' SoftSPI Clock signal
Dim SoftSpi_SDI as sbit at RD4_bit               ' SoftSPI to Data_IN signal
Dim SoftSpi_SDO as sbit at RB5_bit               ' SoftSPI from Data_OUT signal
Dim Chip_Select_Direction as sbit at TRISD0_bit  ' Display Select pin Direction
Dim SoftSpi_CLK_Direction as sbit at TRISD3_bit  ' Clock signal pin Direction
Dim SoftSpi_SDI_Direction as sbit at TRISD4_bit  ' Data_IN signal pin Direction
Dim SoftSpi_SDO_Direction as sbit at TRISB5_bit  ' Data_OUT signal pin Direction

 

'Sub Routines...
Sub Procedure Initialise_Chip
  OSCCON = %01110000           ' Select the 20MHz HS Crystal Oscillator
  LATA = $00                   ' Ensure all outputs are OFF on a RESET
  LATB = $00                   ' Ensure all outputs are OFF on a RESET
  LATC = $00                   ' Ensure all outputs are OFF on a RESET
  LATD = $00                   ' Ensure all outputs are OFF on a RESET
  LATE = $00                   ' Ensure all outputs are OFF on a RESET
  TRISA = %11101111            ' Set the I/O pins direction (1n or 0ut)
  TRISB = %11111111            ' Set the I/O pins direction (1n or 0ut)
  TRISC = %11111000            ' Set the I/O pins direction (1n or 0ut)
  TRISD = %11011111            ' Set the I/O pins direction (1n or 0ut)
  TRISE = %11111111            ' Set the I/O pins direction (1n or 0ut)
  ADCON0 = %00000000           ' Ensure the ADC module is OFF
  ADCON1 = %00001111           ' Set all Analogue inputs for use as Digital I/O
  Chip_Select = 1              ' Deselect the SPI (4*7 LED Display)
  Chip_Select_Direction = 0    ' Set CS# pin as Output
End Sub

 

Sub Procedure AllLEDsGreen
  LATD.5 = 1                   ' LED '5' to Green
  LATC.0 = 1                   ' LED '6' to Green
  LATC.2 = 1                   ' LED '7' to Green
  LATC.1 = 1                   ' LED '8' to Green
End Sub

 

Sub Function DecodeChar(Dim ByRef ConvertChar as Byte) as Byte
'                 ".abcdefg"
  Select Case ConvertChar
    Case 0                       'Decimal Numbers
      DecodeChar = %01111110 '0'
    Case 1
      DecodeChar = %00110000 '1'
    Case 2
      DecodeChar = %01101101 '2'
    Case 3
      DecodeChar = %01111001 '3'
    Case 4
      DecodeChar = %00110011 '4'
    Case 5
      DecodeChar = %01011011 '5'
    Case 6
      DecodeChar = %01011111 '6'
    Case 7
      DecodeChar = %01110000 '7'
    Case 8
      DecodeChar = %01111111 '8'
    Case 9
      DecodeChar = %01111011 '9'
    Case $0A                     ' Hexadecimal Numbers
      DecodeChar = %01110111 'A'
    Case $0B
      DecodeChar = %00011111 'b'
    Case $0C
      DecodeChar = %01001110 'C'
    Case $0D
      DecodeChar = %00111101 'd'
    Case $0E
      DecodeChar = %01001111 'E'
    Case $0F
      DecodeChar = %01000111 'F'
    Case "0"                       'Decimal Characters
      DecodeChar = %01111110 '0'   $7E - HEX equivalent of the BINARY
    Case "1"
      DecodeChar = %00110000 '1'   $30
    Case "2"
      DecodeChar = %01101101 '2'   $3D
    Case "3"
      DecodeChar = %01111001 '3'   $79
    Case "4"
      DecodeChar = %00110011 '4'   $33
    Case "5"
      DecodeChar = %01011011 '5'   $5B
    Case "6"
      DecodeChar = %01011111 '6'   $5F
    Case "7"
      DecodeChar = %01110000 '7'   $70
    Case "8"
      DecodeChar = %01111111 '8'   $7F
    Case "9"
      DecodeChar = %01111011 '9'   $7B
    Case " "                     ' Other Characters
      DecodeChar = %00000000 ' '   $00
    Case "-"
      DecodeChar = %00000001 '-'   $01
    Case "="
      DecodeChar = %00001001 '='   $09
    Case "_"
      DecodeChar = %00001000 '_'   $08
    Case "'"
      DecodeChar = %00100000 '''   $20
    Case $84
      DecodeChar = %00100010 '"'   $22
    Case "A"                     ' Alphabet Characters
      DecodeChar = %01110111 'A'   $77
    Case "B"
      DecodeChar = %00011111 'b'   $1F
    Case "C"
      DecodeChar = %01001110 'C'   $4E
    Case "D"
      DecodeChar = %00111101 'd'   $3D
    Case "E"
      DecodeChar = %01001111 'E'   $4F
    Case "F"
      DecodeChar = %01000111 'F'   $47
    Case "G"
      DecodeChar = %01011110 'G'   $5E
    Case "H"
      DecodeChar = %00110111 'H'   $37
    Case "I"
      DecodeChar = %00110000 'I'   $30
    Case "J"
      DecodeChar = %00111100 'J'   $3C
    Case "K"
      DecodeChar = %10000000 ''   $80
    Case "L"
      DecodeChar = %00001110 'L'   $0E
    Case "M"
      DecodeChar = %10000000 ''   $80
    Case "N"
      DecodeChar = %10000000 ''   $80
    Case "o"
      DecodeChar = %00011101 'o'   $1D
    Case "P"
      DecodeChar = %01100111 'P'   $67
    Case "Q"
      DecodeChar = %10000000 ''   $80
    Case "r"
      DecodeChar = %00000101 'r'   $05
    Case "S"
      DecodeChar = %01011011 'S'   $5B
    Case "t"
      DecodeChar = %00001111 't'   $0F
    Case "U"
      DecodeChar = %00111110 'U'   $3E
    Case "v"
      DecodeChar = %00011100 'v'   $1C
    Case "W"
      DecodeChar = %10000000 ''   $80
    Case "X"
      DecodeChar = %10000000 ''   $80
    Case "y"
      DecodeChar = %00111011 ''   $3B
    Case "Z"
      DecodeChar = %10000000 ''   $80
     Case Else
       DecodeChar = %10000000 ''   $80
  End Select
End Sub

 

Sub Procedure Send2SPI(Dim DisplaySelect, DigitAddress, DigitData as Byte)
  If DisplaySelect = 1 Then    ' Enable the first display
    PORTD.0 = 0                ' Chip Select pin for the first Display
  End If
'  If DisplaySelect = 2 Then    ' Enable the 'nth' Display
'    PORTx.n = 0                ' hip Select pin for the 'nth' Display
'  End If
  Soft_SPI_write(DigitAddress) ' Digit Address 1-4 (and 1-8 for larger displays)
  Soft_SPI_write(DigitData)    ' Display digit or Segment decoding ".abcdefg"
' Just deselct all Displays
  PORTD.0 = 1                  ' Disable the first display
'  PORTx.n = 1                  ' Disable the 'nth' display
End Sub

 

sub procedure max7219_init1
  Send2SPI(1, 0x0C, 0x00)    ' Shutdown Mode
  Send2SPI(1, 0x09, 0x00)    ' Segment decoding ".abcdefg"
'  Send2SPI(1, 0x09, 0xFF)    ' BCD decoding "0123456789-EHLP "
  Send2SPI(1, 0x0A, 0x0F)    ' Segment brightness intensity (0=min - 15=max)
  Send2SPI(1, 0x0B, 0x03)    ' Scan Limit (# of digits 1-8) (NEVER less than 3!)
  Send2SPI(1, 0x0F, 0x00)    ' LampTest OFF
'  Send2SPI(1, 0x0F, 0x01)    ' LampTest ON
'  Send2SPI(1, 0x0C, 0x01)    ' Normal Operation, requires a while to start up
'  Delay_us(250)              ' ..require delay to allow it to fully start-up
'  Send2SPI(1, 0x0C, 0x00)    ' Shutdown Mode
end sub

 

Sub Procedure SendToDisplay(Dim ByRef Message as String[4])
  Message[3]=DecodeChar(Message[3])      ' LSD
  Message[2]=DecodeChar(Message[2])      ' 10s
  Message[1]=DecodeChar(Message[1])      ' 100s
  Message[0]=DecodeChar(Message[0])      ' MSD
  Send2SPI(1, 1, Message[3])             ' LSD
  Send2SPI(1, 2, Message[2])             ' 10s
  Send2SPI(1, 3, Message[1])             ' 100s
  Send2SPI(1, 4, Message[0])             ' MSD
End Sub

 

Sub Procedure Initialise_App
  LATA.4 = 1                 ' Switch on the ACB1 Red LED to show life
  AllLEDsGreen
  Soft_Spi_Init              ' Initialize Soft_SPI
  max7219_init1              ' Initialize  max7219
  Send2SPI(1, 0x0C, 0x01)    ' Start display Normal Operation in selected mode
  Delay_us(250)              ' Time to wake-up MAX7219
  Send2SPI(1, 0x0A, 0x0F)    ' Set Display to full brightness
  SendToDisplay("tESt")      ' Display "splash" screen!
  Delay_ms(500)
  SendToDisplay("    ")
  Delay_ms(250)
  SendToDisplay("----")
  Send2SPI(1, 0x0A, 0x05)    ' Set ~half brightness (0=min-,F=max)
End Sub

 

main:                        ' Code starts to execute here...
  Initialise_Chip                  ' Setup the PIC18F4550
  Initialise_App                   ' Initialize "HeadCode1"
  While True                 ' ..loop MAIN forever
    LATA.4 = NOT PORTA.4     ' Oscillate the ACB1 Red LED to show life
    If PORTB.4=0 Then        ' If PushButton 1 is pressed then..
      AllLEDsGreen
      LATD.5 = 0
      SendToDisplay("1A34")
    End If
    If PORTB.3=0 Then        ' If PushButton 2 is pressed then..
      AllLEDsGreen
      LATC.0 = 0
      SendToDisplay("7H17")
    End If
    If PORTD.7=0 Then        ' If PushButton 3 is pressed then..
      AllLEDsGreen
      LATC.2 = 0
      SendToDisplay("3L22")
    End If
    If PORTD.6=0 Then        ' If PushButton 4 is pressed then..
      AllLEDsGreen
      LATC.1 = 0
      SendToDisplay("1E52")
    End If
    Delay_ms(250)             ' Execute the MAIN LOOP ~4 times a second
  Wend
end.

 

post-12815-0-25969200-1499020193_thumb.jpg

 

 

I will explain the code (and optimise it to reduce its size) but first I need to find a way of posting it so that it is legible!

 

 

Kev.

 

 

Link to post
Share on other sites

  • RMweb Gold

Use the code tags, indicated by the <> icon.

program ACB1_HeadCode1

'Ver 1.0
'300617 - Initial Code
'010717 - Tidying up Code


' Hardware port I/O availability...
'Port A =
' GPA0 = AN0 = RA0
' GPA1 = AN1 = RA1
' GPA2 = AN2 = RA2
' GPA3 = AN3 = RA3
' GPA4 = AN4 = RA5
' GPA5 = AN5 = RE0
' GPA6 = AN6 = RE1
' GPA7 = AN7 = RE2

'Port B =
' GPB0 =     = RD0
' GPB1 =     = RD1
' GPB2 =     = RD2
' GPB3 =     = RD3
' GPB4 =     = RD4
' GPB5 = PGM = RB5
' GPB6 = PGC = RB6
' GPB7 = PGD = RB7

'Port C =
' GPC0 = AN11       = RB4
' GPC1 = AN9/CCP2   = RB3
' GPC2 = P1D        = RD7
' GPC3 = P1C        = RD6
' GPC4 = P1B        = RD5
' GPC5 = T1OSO/T13  = RC0
' GPC6 = P1A        = RC2
' GPC7 = T1OS1/CCP2 = RC1


' Variable declarations section...
Dim DisplayMessage as String[4]  ' Text string to be displayed 0-9,A-Z," -_='


' 4by7 Display Module pin definitions and directions...
Dim Chip_Select as sbit at RD0_bit               ' Display Select (Chip Enable)
Dim SoftSpi_CLK as sbit at RD3_bit               ' SoftSPI Clock signal
Dim SoftSpi_SDI as sbit at RD4_bit               ' SoftSPI to Data_IN signal
Dim SoftSpi_SDO as sbit at RB5_bit               ' SoftSPI from Data_OUT signal
Dim Chip_Select_Direction as sbit at TRISD0_bit  ' Display Select pin Direction
Dim SoftSpi_CLK_Direction as sbit at TRISD3_bit  ' Clock signal pin Direction
Dim SoftSpi_SDI_Direction as sbit at TRISD4_bit  ' Data_IN signal pin Direction
Dim SoftSpi_SDO_Direction as sbit at TRISB5_bit  ' Data_OUT signal pin Direction


'Sub Routines...
Sub Procedure Initialise_Chip
  OSCCON = %01110000           ' Select the 20MHz HS Crystal Oscillator
  LATA = $00                   ' Ensure all outputs are OFF on a RESET
  LATB = $00                   ' Ensure all outputs are OFF on a RESET
  LATC = $00                   ' Ensure all outputs are OFF on a RESET
  LATD = $00                   ' Ensure all outputs are OFF on a RESET
  LATE = $00                   ' Ensure all outputs are OFF on a RESET
  TRISA = %11101111            ' Set the I/O pins direction (1n or 0ut)
  TRISB = %11111111            ' Set the I/O pins direction (1n or 0ut)
  TRISC = %11111000            ' Set the I/O pins direction (1n or 0ut)
  TRISD = %11011111            ' Set the I/O pins direction (1n or 0ut)
  TRISE = %11111111            ' Set the I/O pins direction (1n or 0ut)
  ADCON0 = %00000000           ' Ensure the ADC module is OFF
  ADCON1 = %00001111           ' Set all Analogue inputs for use as Digital I/O
  Chip_Select = 1              ' Deselect the SPI (4*7 LED Display)
  Chip_Select_Direction = 0    ' Set CS# pin as Output
End Sub

Sub Procedure AllLEDsGreen
  LATD.5 = 1                   ' LED '5' to Green
  LATC.0 = 1                   ' LED '6' to Green
  LATC.2 = 1                   ' LED '7' to Green
  LATC.1 = 1                   ' LED '8' to Green
End Sub

Sub Function DecodeChar(Dim ByRef ConvertChar as Byte) as Byte
'                 ".abcdefg"
  Select Case ConvertChar
    Case 0                       'Decimal Numbers
      DecodeChar = %01111110 '0'
    Case 1
      DecodeChar = %00110000 '1'
    Case 2
      DecodeChar = %01101101 '2'
    Case 3
      DecodeChar = %01111001 '3'
    Case 4
      DecodeChar = %00110011 '4'
    Case 5
      DecodeChar = %01011011 '5'
    Case 6
      DecodeChar = %01011111 '6'
    Case 7
      DecodeChar = %01110000 '7'
    Case 8
      DecodeChar = %01111111 '8'
    Case 9
      DecodeChar = %01111011 '9'
    Case $0A                     ' Hexadecimal Numbers
      DecodeChar = %01110111 'A'
    Case $0B
      DecodeChar = %00011111 'b'
    Case $0C
      DecodeChar = %01001110 'C'
    Case $0D
      DecodeChar = %00111101 'd'
    Case $0E
      DecodeChar = %01001111 'E'
    Case $0F
      DecodeChar = %01000111 'F'
    Case "0"                       'Decimal Characters
      DecodeChar = %01111110 '0'   $7E - HEX equivalent of the BINARY
    Case "1"
      DecodeChar = %00110000 '1'   $30
    Case "2"
      DecodeChar = %01101101 '2'   $3D
    Case "3"
      DecodeChar = %01111001 '3'   $79
    Case "4"
      DecodeChar = %00110011 '4'   $33
    Case "5"
      DecodeChar = %01011011 '5'   $5B
    Case "6"
      DecodeChar = %01011111 '6'   $5F
    Case "7"
      DecodeChar = %01110000 '7'   $70
    Case "8"
      DecodeChar = %01111111 '8'   $7F
    Case "9"
      DecodeChar = %01111011 '9'   $7B
    Case " "                     ' Other Characters
      DecodeChar = %00000000 ' '   $00
    Case "-"
      DecodeChar = %00000001 '-'   $01
    Case "="
      DecodeChar = %00001001 '='   $09
    Case "_"
      DecodeChar = %00001000 '_'   $08
    Case "'"
      DecodeChar = %00100000 '''   $20
    Case $84
      DecodeChar = %00100010 '"'   $22
    Case "A"                     ' Alphabet Characters
      DecodeChar = %01110111 'A'   $77
    Case "B"
      DecodeChar = %00011111 'b'   $1F
    Case "C"
      DecodeChar = %01001110 'C'   $4E
    Case "D"
      DecodeChar = %00111101 'd'   $3D
    Case "E"
      DecodeChar = %01001111 'E'   $4F
    Case "F"
      DecodeChar = %01000111 'F'   $47
    Case "G"
      DecodeChar = %01011110 'G'   $5E
    Case "H"
      DecodeChar = %00110111 'H'   $37
    Case "I"
      DecodeChar = %00110000 'I'   $30
    Case "J"
      DecodeChar = %00111100 'J'   $3C
    Case "K"
      DecodeChar = %10000000 ''   $80
    Case "L"
      DecodeChar = %00001110 'L'   $0E
    Case "M"
      DecodeChar = %10000000 ''   $80
    Case "N"
      DecodeChar = %10000000 ''   $80
    Case "o"
      DecodeChar = %00011101 'o'   $1D
    Case "P"
      DecodeChar = %01100111 'P'   $67
    Case "Q"
      DecodeChar = %10000000 ''   $80
    Case "r"
      DecodeChar = %00000101 'r'   $05
    Case "S"
      DecodeChar = %01011011 'S'   $5B
    Case "t"
      DecodeChar = %00001111 't'   $0F
    Case "U"
      DecodeChar = %00111110 'U'   $3E
    Case "v"
      DecodeChar = %00011100 'v'   $1C
    Case "W"
      DecodeChar = %10000000 ''   $80
    Case "X"
      DecodeChar = %10000000 ''   $80
    Case "y"
      DecodeChar = %00111011 ''   $3B
    Case "Z"
      DecodeChar = %10000000 ''   $80
     Case Else
       DecodeChar = %10000000 ''   $80
  End Select
End Sub

Sub Procedure Send2SPI(Dim DisplaySelect, DigitAddress, DigitData as Byte)
  If DisplaySelect = 1 Then    ' Enable the first display
    PORTD.0 = 0                ' Chip Select pin for the first Display
  End If
'  If DisplaySelect = 2 Then    ' Enable the 'nth' Display
'    PORTx.n = 0                ' hip Select pin for the 'nth' Display
'  End If
  Soft_SPI_write(DigitAddress) ' Digit Address 1-4 (and 1-8 for larger displays)
  Soft_SPI_write(DigitData)    ' Display digit or Segment decoding ".abcdefg"
' Just deselct all Displays
  PORTD.0 = 1                  ' Disable the first display
'  PORTx.n = 1                  ' Disable the 'nth' display
End Sub

sub procedure max7219_init1
  Send2SPI(1, 0x0C, 0x00)    ' Shutdown Mode
  Send2SPI(1, 0x09, 0x00)    ' Segment decoding ".abcdefg"
'  Send2SPI(1, 0x09, 0xFF)    ' BCD decoding "0123456789-EHLP "
  Send2SPI(1, 0x0A, 0x0F)    ' Segment brightness intensity (0=min - 15=max)
  Send2SPI(1, 0x0B, 0x03)    ' Scan Limit (# of digits 1-8) (NEVER less than 3!)
  Send2SPI(1, 0x0F, 0x00)    ' LampTest OFF
'  Send2SPI(1, 0x0F, 0x01)    ' LampTest ON
'  Send2SPI(1, 0x0C, 0x01)    ' Normal Operation, requires a while to start up
'  Delay_us(250)              ' ..require delay to allow it to fully start-up
'  Send2SPI(1, 0x0C, 0x00)    ' Shutdown Mode
end sub

Sub Procedure SendToDisplay(Dim ByRef Message as String[4])
  Message[3]=DecodeChar(Message[3])      ' LSD
  Message[2]=DecodeChar(Message[2])      ' 10s
  Message[1]=DecodeChar(Message[1])      ' 100s
  Message[0]=DecodeChar(Message[0])      ' MSD
  Send2SPI(1, 1, Message[3])             ' LSD
  Send2SPI(1, 2, Message[2])             ' 10s
  Send2SPI(1, 3, Message[1])             ' 100s
  Send2SPI(1, 4, Message[0])             ' MSD
End Sub

Sub Procedure Initialise_App
  LATA.4 = 1                 ' Switch on the ACB1 Red LED to show life
  AllLEDsGreen
  Soft_Spi_Init              ' Initialize Soft_SPI
  max7219_init1              ' Initialize  max7219
  Send2SPI(1, 0x0C, 0x01)    ' Start display Normal Operation in selected mode
  Delay_us(250)              ' Time to wake-up MAX7219
  Send2SPI(1, 0x0A, 0x0F)    ' Set Display to full brightness
  SendToDisplay("tESt")      ' Display "splash" screen!
  Delay_ms(500)
  SendToDisplay("    ")
  Delay_ms(250)
  SendToDisplay("----")
  Send2SPI(1, 0x0A, 0x05)    ' Set ~half brightness (0=min-,F=max)
End Sub

main:                        ' Code starts to execute here...
  Initialise_Chip                  ' Setup the PIC18F4550
  Initialise_App                   ' Initialize "HeadCode1"
  While True                 ' ..loop MAIN forever
    LATA.4 = NOT PORTA.4     ' Oscillate the ACB1 Red LED to show life
    If PORTB.4=0 Then        ' If PushButton 1 is pressed then..
      AllLEDsGreen
      LATD.5 = 0
      SendToDisplay("1A34")
    End If
    If PORTB.3=0 Then        ' If PushButton 2 is pressed then..
      AllLEDsGreen
      LATC.0 = 0
      SendToDisplay("7H17")
    End If
    If PORTD.7=0 Then        ' If PushButton 3 is pressed then..
      AllLEDsGreen
      LATC.2 = 0
      SendToDisplay("3L22")
    End If
    If PORTD.6=0 Then        ' If PushButton 4 is pressed then..
      AllLEDsGreen
      LATC.1 = 0
      SendToDisplay("1E52")
    End If
    Delay_ms(250)             ' Execute the MAIN LOOP ~4 times a second
  Wend
end.

Cheers Dutch_Master.

 

It still loses a lot as the colour info is lost but at least the indent and uniform character sizing helps.

 

 

Kev.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...