X

Sunday, April 26, 2009

Programming LCD custom characters

lcdArabic

Before I start, I wanted to make a LCD supports Arabic characters, but :s , first : the max number of stored chars in LCD is 8 :(, ooh ok I can store them in PIC then load each one if needed (as if you have that lots of memory luxury in the PIC :D ), secondly : each damn cell have spacing between each other, so ججج won’t be connected :@ , it will be like : جـ جـ ج, so stopped looking for making it for now, and I found the last resort for using custom characters in LCD is when printing a not supported character in LCD , I think like º (the degree, can be used for math OR temperature(le dr. shereef aho :D ) )and $ .

So how to steps :

  1. You need to initialize you LCD first.

  2. Next you want to move the address register of the LCD to the CGRAM(that will hold the 8 custom characters data), so you will change : RS = 0, R/W = 0 as a start to tell the LCD that you will use Data input (D0-7) as an Instruction. the CGRAM starts from 64 , so to store your (0) char you set D(0-7) = 64, and the next char = last char’s address + 8.

  3. Each character consists of : 8 rows and 5 columns of pixels, you set each row of the 8 sequentially alone for each char, ex. : for a row to light its second pixel (from the right) set it as (010 = 2), there is a pretty script that generates each row’s code from the char you draw, and have the drawing thingy explained better:


       1:  
       2: PORTA.1 = 1 'E = 1
       3: PORTA.2 = 0 'RS = 0
       4: PORTA.3 = 0 'R/W = 0
       5: PORTB = 64  'move AC to 64, 0 character
       6: Delay_ms(5) 
       7: PORTA.1 = 0 'E = 0
       8: Delay_ms(1)
       9:  
      10: PORTA.1 = 1 'E = 1
      11: PORTA.2 = 1 'RS = 1
      12: PORTA.3 = 0 'R/W = 0
      13: PORTB = 14  '01110 , pixel off > 3 pixels on > pixel off
      14: Delay_ms(5)
      15: PORTA.1 = 0
      16: Delay_ms(1)
      17:  
      18: PORTA.1 = 1
      19: PORTA.2 = 1
      20: PORTA.3 = 0
      21: PORTB = 2
      22: Delay_ms(5)
      23: PORTA.1 = 0
      24: Delay_ms(1)
      25:  
      26: PORTA.1 = 1
      27: PORTA.2 = 1
      28: PORTA.3 = 0
      29: PORTB = 12
      30: Delay_ms(5)
      31: PORTA.1 = 0
      32: Delay_ms(1)
      33:  
      34: PORTA.1 = 1
      35: PORTA.2 = 1
      36: PORTA.3 = 0
      37: PORTB = 16
      38: Delay_ms(5)
      39: PORTA.1 = 0
      40: Delay_ms(1)
      41:  
      42: PORTA.1 = 1
      43: PORTA.2 = 1
      44: PORTA.3 = 0
      45: PORTB = 20
      46: Delay_ms(5)
      47: PORTA.1 = 0
      48: Delay_ms(1)
      49:  
      50: PORTA.1 = 1
      51: PORTA.2 = 1
      52: PORTA.3 = 0
      53: PORTB = 17
      54: Delay_ms(5)
      55: PORTA.1 = 0
      56: Delay_ms(1)
      57:  
      58: PORTA.1 = 1
      59: PORTA.2 = 1
      60: PORTA.3 = 0
      61: PORTB = 14
      62: Delay_ms(5)
      63: PORTA.1 = 0
      64: Delay_ms(1)
      65:  
      66: PORTA.1 = 1
      67: PORTA.2 = 1
      68: PORTA.3 = 0
      69: PORTB = 0
      70: Delay_ms(5)
      71: PORTA.1 = 0
      72: Delay_ms(1)

    if you want to add just continue adding rows after the eighth row for the last char, and the row will be added for the next char, if you want to jump to a certain char of the 8 supported , move the AC -as in step 2- to 64 + N * 8, a small note : the 8th row will not appear if the scroll is enabled.

  1. Jump BACK to the last data address (last character you printed on the screen) to resume printing, so if you start by defining your custom chars and then start printing, you can jump to 128 address (Start of DDRAM), but if you already printed then jumped to CGRAM you need to return to the same address AC was in before going to CGRAM, so you can keep track of the number of chars printed so that you can later return, OR you can read the AC just before jumping to CGRAM storing it and use it to return later the later solution I have spent about an hour trying it, but I couldn’t do it in simulation mode :s, I tried every thing but D(0-7) never outputs AC.

  2.    1: PORTA.1 = 1 'E = 1
       2: PORTA.2 = 0 'RS AND R/W = 0
       3: PORTA.3 = 0
       4: PORTB = 128 'return to DataRAM start postion = 128
       5: Delay_ms(5)
       6: PORTA.1 = 0
       7: Delay_ms(1)

  3. Live you regular life and print characters as you want, if needed to print a custom one , just set D(0-7) to N , where N is the number of the cust char in CGRAM :
  4.    1: PORTA.1 = 1 'E = 1
       2: PORTA.2 = 1 ' RS = 1 , R/W = 0
       3: PORTA.3 = 0
       4: PORTB = 0   'Print custom char 0
       5: Delay_ms(5)
       6: PORTA.1 = 0
       7: Delay_ms(1)
       8:
       9:  
      10:  
      11: PORTA.1 = 1
      12: PORTA.2 = 1
      13: PORTA.3 = 0
      14: PORTB = 1   'Print custom char 1, and so on to 8
      15: Delay_ms(5)
      16: PORTA.1 = 0
      17: Delay_ms(1)

As for the return thing if you already have been printing before moving to CGRAM, then if you returned to 128 again and print it will overwrite the already printed chars.

2 comments:

andy said...

In today’s internet savvy world an online presence is a must for any organization weather big or small, but just a mere website of the company wont serve the purpose of reaching out and impressing the target audience, your online presence should leave an impact on the mind of the viewers, and from here comes website designing and development companies of Delhi, search engine optimization and marketing companies of Delhi and internet marketing services providing companies of Delhi in picture. These companies provide end to end solutions for all your website related issues.

Anonymous said...

this has been very very helpful. thank you!!

Post a Comment

Newer Posts Older Posts Home