PIC16F84A ile LCD LM052L 'de Nasil String gösterdebilirim??

Başlatan Digimensch, 31 Ekim 2004, 14:50:59

Digimensch

Elimde bir tane LCD LM052L  var.
Bu LCD'de   PIC16F84 icine yazdigim bir Stringi nasil gösterebilirim??
PicBasic ile  PIC icin nasil kod yazmaliyim?
Kodun mantigini ögrenmek istiorum.
Yani PIC16F84 calistiginda LCD'de  örnegin  "Bu bir Denemedir"  stringini nsil yazdirabilirim??

fsan

merhaba Ugur,
Picbasic pro da LCD yi asagidaki semadaki gibi baglarsan

LCDOUT $FE, 1, "Bu bir Denemedir"

yazman yeterli olacak.

LCD de solda "Vss" yazan yer Pin-1



detaylar icin bu linke bir gözat
http://www.rentron.com/PicBasic-LCD.htm

Sevgiler, saygilar..
/Fikret

fsan

LCDOUT  Prints data on LCD display

Syntax: LCDOUT  Data {, Data...}
Description: LCDOUT sends the data to the LCD (Liquid Crystal Display). PIC BASIC supports various LCD models which have Hitachi 44780 controller or compatible one. LCD usually has either 14 or 16 pins for connection to a microcontroller. If there is character # before data, ASCII value of every data is sent to LCD. LCDOUT has the same modifiers as the instruction SEROUT2.


Modifier Sends
{I}{S} BIN{1..16} binary number
{I}{S} DEC{1..5}  decimal number
{I}{S} HEX{1..4}  hexadecimal number
REP c/n character c repeated n times
STR ArrayVar {\n} n character string



Before the first instruction is sent to LCD, program should wait for at least half a second for LCD to initialize.

LCD display can be connected to PIC microcontrollers by either 4-bit or 8-bit bus. If 8-bit bus is used, all of 8 bits must be connected to the same port, while in the case of 4-bit bus all 4 bits must be either in the upper or the lower part of byte. R/W line should be connected to ground if LCD is used only for data display. PIC BASIC assumes that LCD is connected to specific pins if DEFINE directives do not say otherwise. Default is 4-bit bus with lines DB4-DB7 connected to RA0-RA3, RS pin connected to RA4 and E pin connected to RB 3. Also, it is assumed that LCD is 2x16. For changing any of the default settings, appropriate DEFINE directives can be used.

If LCD is connected to some other microcontroller lines it has to be defined with DEFINE directives, as shown in the following example.

 

DEFINE LCD_DREG    PORTB              Â‘ port selection

DEFINE LCD_DBIT      4                   ‘ initial bit (0 or 4) selection in case of 4-bit bus

 

DEFINE LCD_RSREG   PORTB            Â‘ port Register select

DEFINE LCD_RSBIT    1                   ‘ Register Select bit

DEFINE LCD_EREG     PORTB            Â‘ Enable port

DEFINE LCD_EBIT      0                   ‘ Enable bit

DEFINE LCD_BITS      4                   ‘ bus size – 4 or 8 bits

DEFINE LCD_LINES     2                   ‘ number of LCD lines

DEFINE LCD_COMMANDS  2000         ‘ command delay in microseconds

DEFINE LCD_DATAUS    50               ‘ data delay in microseconds

 

Definitions above define 2-line LCD on 4-bit bus on the upper 4 bits of microcontroller port D. Register Select (RS pin) is on PORTD.2 and Enable is on PORTD.3.

Every LCD controller is in charge of certain commands. Commands are sent by instruction: LCDOUT $FE, $Kod. List of commands is shown in table below.

 

Command Operation
$FE, 1 clear display
$FE, 2  Return home (beginning of the first line)
$FE, $0C  Turn off cursor
$FE, $0E  Underline cursor on
$FE, $0F  Blinking cursor on
$FE, $10 Shifting cursor left
$FE, $14  Shifting cursor right
$FE, $C0 set cursor to the beginning of the second line
$FE, $94  set cursor to the beginning of the third line
$FE, $D4  set cursor to the beginning of the fourth line


Example:   

B0 var byte 
B1 var byte 

Main: 

lcdout  $FE, 1, "Hello" '  Clear display and print "Hello" 
lcdout  $FE, $C0        '  Switch to second line 
lcdout  B0                '  Display the value of B0 
lcdout  #B1   '  Display the value of B1 in ASCII code 

Loop: 
goto Loop 

end

Digimensch

Saol Hocam,
Ben simdi bir LCD'ye yazi yazdirmak istedigimde bu tanimlamalari yapmam lazimmi??
Define LCD_DREG PORTA 
Define LCD_DBIT 0 
Define LCD_RSREG PORTA 
Define LCD_RSBIT 4 
Define LCD_EREG PORTB 
Define LCD_EBIT 3 
Define LCD_LINES 2 
Define LCD_BITS 4


Birde bende söyle bir örnek vardi fakat gerekli bas dosyasini yanlislikla sildim.Burda Pic calistogonda ekrana yazi yazdiriyordu.


Simdi senin verdigin yukatrdaki kodu buna uyarlarsam nasil olur acaba bir deneme yapayim.

Digimensch

Yukardaki Devreye söyle bir Kod yazdim.

  define  lcd_dreg    portb
   define  lcd_dbit    4
   define  lcd_rsreg   portb
   define  lcd_rsbit   0
   define  lcd_ereg    portb
   define  lcd_ebit    1
   define  lcd_bits    4
   define  lcd_lines   2


start:
      Pause 250
      lcdout $fe,1
      lcdout "Ugur"
      Pause 205
      lcdout $fe,$c0
      lcdout "Yalcin"
      Pause 250
      goto start
end


Bayagi güzel oldu

fsan

Ugur,
Picbasic pro da bu tanimlamalarin (define lerin) cogu default var zaten.
Sen programi compile edince pbp compiler define'lerde degisiklik varmi yokmu diye control edip, bir degisklik yoksa kendi default tanimlamalarini kullaniyor..

MicroCode studio "help topics" de Picbasic komutlari ile ilgili cok sey harika bir sekilde hazirlanmis ve oraya konulmus benim "Search" özelligini kullanarak girdigim "define" kelimesi, define ile ilgili asagidaki listeyi cikardi.

Alıntı YapDEFINE

Some elements, like the clock oscillator frequency and the LCD pin locations, are predefined in PBP. DEFINE allows a PICBasic PRO program to change these definitions if desired. These definitions must be in all upper case.

DEFINE ADC_BITS 8 'Number of bits in ADCIN result
DEFINE ADC_CLOCK 3 'ADC clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 'ADC sampling time in microseconds
DEFINE BUTTON_PAUSE 10 'Button debounce delay in ms
DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit
DEFINE CHAR_PACING 1000 'Serout character pacing in us
DEFINE DEBUG_REG PORTB 'Debug pin port
DEFINE DEBUG_BIT 0 'Debug pin bit
DEFINE DEBUG_BAUD 2400 'Debug baud rate
DEFINE DEBUG_MODE 1 'Debug mode: 0 = True, 1 = Inverted
DEFINE DEBUG_PACING 1000 'Debug character pacing in us
DEFINE DEBUGIN_REG PORTB 'Debugin pin port
DEFINE DEBUGIN_BIT 0 'Debugin pin bit
DEFINE DEBUGIN_MODE 1 'Debugin mode: 0 = True, 1 = Inverted
DEFINE HPWM2_TMR 1 'Hpwm 2 timer select
DEFINE HPWM3_TMR 1 'Hpwm 3 timer select
DEFINE HSER_BAUD 2400 'Hser baud rate
DEFINE HSER_CLROERR 1 'Hser clear overflow automatically
DEFINE HSER_SPBRG 25 'Hser spbrg init
DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 20h 'Hser transmit status init
DEFINE HSER_EVEN 1 'Use only if even parity desired
DEFINE HSER_ODD 1 'Use only if odd parity desired
DEFINE I2C_HOLD 1 'Pause I2C transmission while clock held low
DEFINE I2C_INTERNAL 1 'Use for internal EEPROM on 16CExxx and 12CExxx
DEFINE I2C_SCLOUT 1 'Set serial clock to bipolar instead of open-collector
DEFINE I2C_SLOW 1 'Use for >8MHz OSC with standard speed devices
DEFINE I2C_SDA PORTA,0 'Data pin for I2C (12-bit core only)
DEFINE I2C_SCL PORTA,1 'Clock pin for I2C (12-bit core only)

DEFINE LCD_DREG PORTA 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTA 'LCD register select port
DEFINE LCD_RSBIT 4 'LCD register select bit
DEFINE LCD_EREG PORTB 'LCD enable port
DEFINE LCD_EBIT 3 'LCD enable bit
DEFINE LCD_RWREG PORTE 'LCD read/write port
DEFINE LCD_RWBIT 2 'LCD read/write bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us

DEFINE LOADER_USED 1 'Bootloader Used
DEFINE NO_CLRWDT 1 'Forces manual use of CLRWDT
DEFINE ONINT_USED 1 'Serves as LOADER_USED for versions before 2.33
DEFINE PULSIN_MAX 1000 'Maximum counts allowed before pulsin times out
DEFINE OSC 4 'Oscillator speed in MHz: 3(3.58 ) 4 8 10 12 16 20 24 25 32 33 40
DEFINE OSCCAL_1K 1 'Set OSCCAL for PIC12C671/CE673
DEFINE OSCCAL_2K 1 'Set OSCCAL for PIC12C672/CE674
DEFINE SER2_BITS 8 'Set number of data bits for Serin2 and Serout2
DEFINE SER2_ODD 1 'Use odd parity instead of even parity
DEFINE SHIFT_PAUSEUS 50 'Slow down the Shiftin and Shiftout clock
DEFINE USE_LFSR 1 'Use 18Cxxx LFSR instruction
DEFINE XINXLAT_OFF 1 'Don't translate Xin commands to BS2 format
DEFINE XOUTXLAT_OFF 1 'Don't translate Xout commands to BS2 format  

Copyright © 2002 microEngineering Labs, Inc.
All rights reserved.

yukarida LCD ile ilgili "Define" kisimlara bakarsan LCD pin'lerin  PIC'teki default PORT/pins baglantilarini göreceksin.
Sende LCD baglantilarini o sekilde yaparsan LCD baglanti tanimlamalarini yazmana gerek yok. Sen yukaridaki proteus ile yaptigin simulasyonda default tanimlamada olmayan pinler kullandigin icin tanimlama yapman gerekiyordu ve sende onu yapmissin zaten :)

basarilar..

Digimensch

Bu arada LCD icin bazi komutlarda ögrendim.
Bunuda burda benim gibi yeni baslayan arkadaslarla paylasmak isterim.
LCD icin bazi PicBasic Komutlari ve anlamlari: 
$FE, 1 -------------> Ekrani sil 
$FE, 2 -------------> 1.Linie'ye dön 
$FE, $0C ----------> Cursor'u off yap 
$FE, $0E ----------> Cursar'i (-) seklinde göster 
$FE, $0F ----------> Cursor'a Blink(yan-sön) yaptir 
$FE, $10 ----------> Cursor'u bir Positsiyon sola kaydir 
$FE, $14 ----------> Cursor'u bir Positsiyon saga kaydir 
$FE, $C0 ----------> Cursor'u 2.Linie'nin basina götür



Fakat simdi bunlarin anlamlarini hala kavrayamadim.
  define  lcd_dreg    portb  
burda lcd_reg nedir? portb'nin hangi bitine takilmasi gerek oldugunu nasil anlarim??

  define  lcd_dbit    4
burda lcd_dbit nedir? 4 neyi ifade ediyor??
.
.
.
  define  lcd_rsreg   portb
  define  lcd_rsbit   0
  define  lcd_ereg    portb
  define  lcd_ebit    1
  define  lcd_bits    4
  define  lcd_lines   2

yani yukardaki kavramlar tam neyi anlatiypr??

fsan

DEFINE LCD_DREG PORTA 'LCD data port
'* LCD data pinler: D4-D7 4-bit modunda kullanilacaksa
'* LCD data pinler: D0-D7 8-bit modunda kullanilacaksa
'* PIC'te hangi porta baglanacak? burada PORTA ya baglanmis

DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
LCD 4-bit modunda kullanilacaksa: (LCD pins D4-D7)
LCD_DBIT 0 olunca LCD pinler: D4-D7 PIC'te PORTA.0-3 pinlere baglanacak
LCD_DBIT 1 olunca LCD pinler: D4-D7 PIC'te PORTA.4-7 pinlere baglanacak

DEFINE LCD_RSREG PORTA 'LCD register select port
'* LCD RS pin PIC'te hangi porta baglanacak? burada PORTA ya baglanmis

DEFINE LCD_RSBIT 4 'LCD register select bit
'* LCD RS pin PIC'te hangi pine baglanacak? burada PORTA.4 e  baglanmis

DEFINE LCD_EREG PORTB 'LCD enable port
'* LCD E pin PIC'te hangi porta baglanacak? burada PORTB ye baglanmis

DEFINE LCD_EBIT 3 'LCD enable bit
'* LCD E pin PIC'te hangi pine baglanacak? burada PORTB.3 e   baglanmis

DEFINE LCD_RWREG PORTE 'LCD read/write port
'* LCD R/W pin PIC'te hangi porta baglanacak? burada PORTE ye baglanmis
'* LCD R/W pin genelde bu pin'i PIC'e değil GND'ye bagliyoruz..

DEFINE LCD_RWBIT 2 'LCD read/write bit
'* LCD R/W pin PIC'te hangi pine baglanacak? burada PORTE.2 ye  baglanmis
'* LCD R/W pin genelde bu pin'i PIC'e değil GND'ye bagliyoruz..

DEFINE LCD_BITS 4 'LCD bus size 4 or 8
'*iste burada LCD nin hangi Modu kullanacagini belirliyoruz
'* LCD 4-bit modunda kullanilacaksa: (LCD pins D4-D7) LCD_BITS 4 yaziyoruz
'* LCD 8-bit modunda kullanilacaksa: (LCD pins D0-D7) LCD_BITS 8 yaziyoruz

DEFINE LCD_LINES 2 'Number lines on LCD
'* LCD de kac satir (line) var onu yaziyoruz
'* Senin yukarida bahsettigin LM052L de 2 satir var  (2 lines x 16 cols. LCD)  

*'Bu asagidakiler de sanirim zamanlama (timing) ile ilgili..
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us


hepsi bu kadar :)