• PicŪ Basic

  • Bringing a M50530 lcd to life

    Got a M50530 and don't know what to do with it? Start bring it to life with this routine.

    ;LCD display use , based on M50530 controller
    ;here using 3x40 type

    Device 16F876
    XTAL = 4
    TRISB=000000 ;this one to avoid LCD hang, as we don't read nothing from PortB but send
    ;-------------M50530 DECLARES--------------------------------------------------------
    Symbol rw = PORTB.2
    Symbol L1 = PORTB.1
    Symbol L2 = PORTB.0
    Symbol e = PORTB.3
    ; the LCD's data lines D7,D6,D5,D4 connect to PortB 7,6,5,4 respectively
    Dim cg_code As Byte
    Dim xx As Byte ;cursor x position 0 to 39 in the case of 40 character/line LCD
    Dim yy As Byte ;cursor y position 0 to 2 in the case of 3 Lines LCD
    Dim b As Byte
    Dim lcd_str[11] As Byte ;this should be changed as of Note_1
    Dim caracter As Byte
    Dim str_caracter As Byte
    Dim car0 As lcd_str#0 ;next variables needed for the print string macro/routine
    Dim car1 As lcd_str#1
    Dim car2 As lcd_str#2
    Dim car3 As lcd_str#3
    Dim car4 As lcd_str#4
    Dim car5 As lcd_str#5
    Dim car6 As lcd_str#6
    Dim car7 As lcd_str#7
    Dim car8 As lcd_str#8
    Dim car9 As lcd_str#9
    Dim car10 As lcd_str#10
    ;Insert here dim's for your_needed_value as for Note_1

    ;------------END OF M50530 DECLARES--------------------------------------------------

    Dim numbers As Byte

    DelayMS 500
    GoSub init
    GoTo main

    ;PRINT STRING Subroutine - used for string or variable display
    ;SEE Note_1 : the string you want to be displayed should have a maximum of 15 characters
    ; if different characters number needed in the print_str string then change
    ; Note_1 like: for caracter = 0 to (your_needed_value - 1) together with modifying
    ; the next line: LOOKUPL caracter,[car0,......car(your_needed_value - 1),0]str_caracter, and
    ; off course change the dim's for the lcd_str array, array components dim's and clear_str Label
    For caracter = 0 To 9 ; Note_1
    LookUpL caracter,[car0,car1,car2,car3,car4,car5,car6,car7,car8,car9, 0],str_caracter
    If str_caracter = 0 Then str_caracter = $20
    PORTB = str_caracter & $f0 : L2=1:PulsOut e,1:PORTB = str_caracter << 4: L2=1: PulsOut e,1
    GoSub clear_str
    clear_str: For b = 0 To 9 ; Note_1 ( for b = 0 to (your_needed_value - 1)
    Clear lcd_str[b]
    transfer: ;this one needed cursor positioning in the case of 40 characters/line LCD
    b = (yy*40)+xx
    PORTB = b & $f0:L1=1:L2=1:PulsOut e,2:PORTB = b << 4:L1=1:L2=1:PulsOut e,2
    clear_screen: PORTB=$0 : PulsOut e,1elayUS 10: PORTB=$10: PulsOut e,1: DelayUS 100 ' CH
    cursor_at MACRO igrec, ics ; CURSOR positioning macro
    num_byte igrec, yy ;
    num_byte ics, xx
    Call transfer
    cls_lcd MACRO
    Call clear_screen
    init:;M50530 INIT FOR STARTUP
    ;portb=$30: pulsout e,10:delayms 100: portb=$f0: pulsout e,10: delayms 100 ' SD Cursor Blink
    PORTB=110000: PulsOut e,1elayUS 10: PORTB=000000: PulsOut e,1: DelayUS 100 ' SD no blink
    PORTB=$50: PulsOut e,1elayUS 10: PORTB=$80: PulsOut e,1: DelayUS 100 ' SE
    PORTB=$d0: PulsOut e,1elayUS 10: PORTB=$b0: PulsOut e,1: DelayUS 100 ' SF
    ;portb=$0 : pulsout e,1:delayus 10: portb=$10: pulsout e,1: delayus 100 ' CH
    ;portb=010000: pulsout e,10: portb=000000: pulsout e,10 ' MA
    GoSub clear_str
    numbers = 235 ; this value for the example of a variable display

    cursor_at 0,0: StrN lcd_str = Str$(DEC3 numbers):GoSub print_str ; variable display

    cursor_at 2,10: StrN lcd_str = "LCD Macros":GoSub print_str ; string display
    cursor_at 1,20: StrN lcd_str = "M50530":GoSub print_str
    cursor_at 0,10: StrN lcd_str = "Proton+":GoSub print_str

    cursor_at 2,20 : PORTB=$DF & $f0: L2=1: PulsOut e,1:PORTB= $DF <<4:L2=1:PulsOut e,1 ;Degrees symbol
    ; in the case of displaying special caracters like Degrees symbol, then just change $DF as stated above
    ; with the code for your needed special character from the M50530 datasheet

    DelayMS 1500 ;
    cls_lcd ; clear screen for the M50530
    DelayMS 1500 ;pause for drama

    GoTo main ;

    By Gabi Mihaila

  • Recent Activity


    Mid$ not recognised

    Thread Starter: John Drew

    I'm trying to use Mid$ on a string using the 16F1827 which is an enhanced device. The compiler doesn't recognise the MID$. The compiler does...

    towlerg Today, 14:22 Go to last post