Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 21st July 2007, 10:31 AM   (permalink)
Default

Hi Tim,

The SX/B BASIC docs say it's a compiler not an interpretor and it really looks like a simple, capable, intuitive BASIC implementation. Let me study it a little more. I'm sure there's got to be a way to access a 64 byte display buffer quickly and efficiently (perhaps using GET and PUT or more directly using @address_of operations).

Don't "jump ship" for another processor yet. You listed some very good reasons for why you're developing with the SX family.

Later, Mike
Mike, K8LH is offline   Reply With Quote
Old 21st July 2007, 11:35 AM   (permalink)
Default

Mike,

Your right it is a compiler not an interpretor. I use those words interchangibly and I should not.

Look at this code example that shows how to have a large array of 64 from an SX28 limited 16 byte array. Although I never quite figured it out how to use it in past applications. Let me know if this helps or not. I have plenty more code examples from Jon Williams (guy that wrote the PDF book - also known as JonnyMac).

I zipped it along with all of the others that may be helpfull to you. Look at Big_Array.sxb and WREAD.sxb in particular. Many of the other complete programs have good subroutines in them too.

Thanks.
Attached Files
File Type: zip SX Code.zip (885.4 KB, 6 views)
tdg8934 is offline   Reply With Quote
Old 21st July 2007, 11:18 PM   (permalink)
Default

Tim,

I'll take a closer look at SX/B during the coming week. Meanwhile for your amusement and for those PIC users who may be considering purchasing one of those $12.90 USD 16x32 modules, here's an updated (untested) version of PIC demo software using Swordfish BASIC that features PWM brightness control and an improved performance assembly code ISR driver.

Mike

Code:
{
*********************************************************************
*  Name    : OEM 16x32 Display v3.BAS                               *
*  Author  : Mike McLaren, K8LH                                     *
*  Notice  : Copyright (c) 2007, Micro Applications Consultants     *
*          : All Rights Reserved                                    *
*  Date    : 07/21/07                                               *
*  Version : 3.0                                                    *
*  Notes   : v3 software features PWM brightness control and an     *
*          : assembly code ISR driver for improved performance      *
*          :                                                        *
*********************************************************************
}
Device = 18F2520
Clock = 16

Dim Display(16) As LongWord,        ' full 32 bit row size elements
    TempRow As LongWord             ' temp 32 bit variable

Dim i As Byte,                      '
    Row As Byte,                    ' row number, range 0..15
    Counter As Byte,                ' ISR counter var'
    RowPos As Word,                 ' 16 bit row ring counter
    Work0, Work1, Work2 As Word     ' 16 bit ISR work registers
    
{
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  scan 1 of 16 rows each 1 msec interrupt                          '
'                                                                   '
'  265 cycles, 53.0 usecs, 5.30% ISR processing "overhead"          '                                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
Interrupt TMR2_Interrupt()
ASM
SR1     equ     0               ;' SR1 pin RB0 (row SR)
SR2     equ     1               ;' SR2 pin RB1 (column 1 SR)
SR3     equ     2               ;' SR3 pin RB2 (column 2 SR)
CLK     equ     3               ;' CLK pin RB3 (all SR's)
LAT     equ     4               ;' LAT pin RB4 (all SR's)

        bcf     PIR1,1          ;' clear Timer 2 interrupt flag
        rlncf   Row,W           ;' row number (0..15) x4
        rlncf   WREG,W          ;'
        addlw   Display         ;'
        movwf   FSR1L           ;' FSR1 = Display(Row).byte0
        clrf    FSR1H           ;'
        movff    POSTINC1,Work0+0
        movff    POSTINC1,Work0+1
        movff    POSTINC1,Work1+0
        movff    POSTINC1,Work1+1
        movff    RowPos+0,Work2+0
        movff    RowPos+1,Work2+1
        bsf     Counter,4       ;' counter = 16
v0      movlw   b'00000010'     ;' preload WREG
        rlcf    Work1+0,F       ;' rlcf lo byte
        rlcf    Work1+1,F       ;' rlcf hi byte
        rlcf    WREG,F          ;' pick up b2 (2nd column SR)
        rlcf    Work0+2,F       ;' rlcf lo byte
        rlcf    Work0+3,F       ;' rlcf hi byte
        rlcf    WREG,F          ;' pick up b1 (1st column SR)
        rlcf    Work2+4,F       ;' rlcf lo byte
        rlcf    Work2+5,F       ;' rlcf hi byte
        rlcf    WREG,F          ;' pick up b0 (row SR)
        movwf   LATB            ;' update port, [--010ddd]
        bsf     LATB,CLK        ;' toggle <CLK> [--011ddd]
        decfsz  Counter,F       ;' all 16 iterations?
        bra     v0              ;' no, branch, else
;'
;'  latch 48 bits of new SR data onto the driver IC outputs
;'
        bcf     LATB,LAT        ;' toggle <LAT> [--001ddd]
        bsf     LATB,LAT        ;' toggle <LAT> [--011ddd]
;'
;'  advance Row variable and RowPos ring counter for the next cycle
;'
        incf    Row,W           ;' Row++
        bcf     Row,4           ;' Row = Row % 16 (sort of)
        rrcf    RowPos+0,W      ;' rrcf lo byte into W to preserve C
        rrcf    RowPos+1,F      ;' rrcf hi byte
        rrcf    RowPos+0,F      ;' rrcf lo byte
End ASM
End Interrupt

{
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  init PWM sub                                                     '
'                                                                   '
'  the STB inputs on all three 16 bit serial-to-parallel drivers    '
'  should be connected to the RC2/CCP1 "PWM" output                 '
'                                                                   '
'  the PWM period (and interrupts) are 1.0 msecs.  adjust display   '
'  brightness by setting PWM duty cycle value in CCPR1L;            '
'                                                                   '
'  CCPR1L = 50      ' 20% duty cycle, 80% brightness                '
'  CCPR1L = 100     ' 40% duty cycle, 60% brightness                '
'  CCPR1L = 150     ' 60% duty cycle, 40% brightness                '
'  CCPR1L = 250     '100% duty cycle, Display is off                '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
Sub Init_PWM()
    TMR2 = 0                        ' clear TMR2 register
    PIR1 = 0                        ' clear interrupt flags
    T2CON = %00000010               ' '00000010'
                                    ' '-0000---', postscale 1:1
                                    ' '-----0--', TMR2 off
                                    ' '------10', prescale 16:1
                                    ' for 4-us Timer 2 'ticks'
    PR2 = 250 - 1                   ' 250 * 4 us = 1 msec PWM period
                                    ' and interrupt rate
    CCP1CON = %00001100             ' '00001100'
                                    ' '00------', unused bits
                                    ' '--00----', duty cycle lsb's
                                    ' '----1100', PWM mode
    CCPR1L = 25                     ' 10% duty cycle, 90% brightness
    PIE1.1 = 1                      ' enable Timer 2 interrupts
    INTCON.6 = 1                    ' enable peripheral interrupts
    T2CON.2 = 1                     ' turn on Timer 2
End Sub

{
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  program                                                          '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
Row = 0                             ' init Row
RowPos = %1000000000000000          ' init RowBit ring counter
Counter = 0                         ' init ISR counter var'

ADCON1 = %00001111                  ' setup RB3..RB0 to digital mode
PORTB = %00010000                   ' setup PORTB (SR <LAT> bit hi)
TRISB = %00000000                   ' PORTB all outputs

Init_PWM                            ' init PWM & Timer 2 interrupts
Enable(TMR2_Interrupt)              ' enable global interrupts

{ 1st frame }
                                                          
Display(0) = %11111111111111111111111111111111
Display(1) = %01111111111111111111111111111110
Display(2) = %00111111111111111111111111111100
Display(3) = %00011111111111111111111111111000
Display(4) = %00001111111111111111111111110000
Display(5) = %00000111111111111111111111100000
Display(6) = %00000011111111111111111111000000
Display(7) = %00000001111111111111111110000000
Display(8) = %00000000111111111111111100000000
Display(9) = %00000000011111111111111000000000
Display(10)= %00000000001111111111110000000000
Display(11)= %00000000000111111111100000000000
Display(12)= %00000000000011111111000000000000
Display(13)= %00000000000001111110000000000000
Display(14)= %00000000000000111100000000000000
Display(15)= %00000000000000011000000000000000

{ additional frames }

For i = 0 To 64
    TempRow = Display(15)           ' save bottom row temporarily
    Display(15) = Display(14)       ' downward repeating scroll
    Display(14) = Display(13)
    Display(13) = Display(12)
    Display(12) = Display(11)
    Display(11) = Display(10)
    Display(10) = Display(9)
    Display(9)  = Display(8)
    Display(8)  = Display(7)
    Display(7)  = Display(6)
    Display(6)  = Display(5)
    Display(5)  = Display(4)
    Display(4)  = Display(3)
    Display(3)  = Display(2)
    Display(2)  = Display(1)
    Display(1)  = Display(0)
    Display(0)  = TempRow
    DelayMS(100)                    ' delay 100 msecs per change
Next
End

Last edited by Mike, K8LH; 22nd July 2007 at 10:30 AM.
Mike, K8LH is offline   Reply With Quote
Old 31st July 2007, 07:37 PM   (permalink)
Default

Someone wrote me off list to ask about how you might use the PWM brightness control.

To make it a little easier to deal with and perhaps understand I created a subroutine in Swordfish BASIC to adjust the brightness setting which is actually the inverse of the PWM duty cycle.
Code:
{
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  Sub Brightness(0..100)     0% black to 100% full brightness      '
'                                                                   '
'  15 cycles, 3.75 usecs (16 MHz), including call and return        ' 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
}
Sub Brightness(pPercent As Byte)    ' CCPR1L = (250-(pPercent*2.5))
    Dim Temp As Byte                ' 
    Temp = pPercent * 2             '
    Temp = Temp + (pPercent >> 1)   '
    CCPR1L = 250 - Temp             ' set PWM duty cycle
End Sub                             '
Simply add a line in your MAIN program to change the display brightness level;
Code:
    Brightness(70)                  ' set brightness to 70% of full
Now you probably could also use the Brightness control to fade-to-black from the current level, put new information into the display buffer, then fade-from-black back to the current level, but, I would probably synchronize the brightness level changes to 16 row "frames" to avoid unwanted display artifacts. Sample fade-to-black code might look something like this;
Code:
{ display fade-to-black }

i = Level                           ' copy current 'Level'
While i <> 0                        ' fade from 'Level' to black
    While Row <> 15                 ' sync' to 16 row 'frame'
    Wend                            '
    Brightness(i)                   ' change brightness setting
    While Row <> 0                  ' wait for row 0 
    Wend                            '
    i = Integer(i - 5)              '
Wend                                '
Brightness(0)                       ' force black

Last edited by Mike, K8LH; 3rd August 2007 at 01:13 AM.
Mike, K8LH is offline   Reply With Quote
Old 1st August 2007, 11:17 AM   (permalink)
Default

Mike,

I thank you for your subroutine but I'm not quite following how it is to be applied in the Main routine. I would think brightness is controlled by the current limiting resistors so how is the Brightness control to be applied via software?

Thanks again.
tdg8934 is offline   Reply With Quote
Old 1st August 2007, 11:40 AM   (permalink)
Default

Quote:
Originally Posted by tdg8934
Mike,

I thank you for your subroutine but I'm not quite following how it is to be applied in the Main routine. I would think brightness is controlled by the current limiting resistors so how is the Brightness control to be applied via software?
The current limiting resistors control the MAXIMUM brightness, you can use PWM to adjust it anywhere between that maximum and zero.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now   Reply With Quote
Old 3rd August 2007, 01:18 AM   (permalink)
Default

Quote:
Originally Posted by tdg8934
Mike,

I thank you for your subroutine but I'm not quite following how it is to be applied in the Main routine. I would think brightness is controlled by the current limiting resistors so how is the Brightness control to be applied via software?

Thanks again.
Sorry. I assumed that varying the brightness of a single LED using PWM was almost "basic studies" for anyone playing with microcontrollers these days. My first PWM experiment was varying the speed of a 12vdc fan.

Not sure where to refer you for study and you already know I'm not very good at explaining things.
Mike, K8LH is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Problem with LCD code? spondootre Micro Controllers 15 29th April 2008 09:15 AM
microchip application A590 /display is ok now prosound90 Micro Controllers 20 18th November 2006 09:44 PM
Display Driver for 16 * 16 matrix display pmphilip General Electronics Chat 2 4th January 2006 07:14 PM
Datasheet for display driver for LM-1256(MATRIX DISPLAY) pmphilip Datasheet/Parts Requests 1 25th January 2005 07:25 PM



All times are GMT. The time now is 10:29 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.