EL1602B
Jan Blepta
xbleptaj
Středa Březen 17 12:05:40 CET 2004
proc to nechodi nevim podrobne jsem to neprohlizel,
jen Vam dam tip, aby jste prepsal systemovou fci putchar,
pak zahrnete <stdio.h> a muzete pouzivat printf("Ahoj vole..%I", (unsigned)
promenna);
nebo i float promenne :printf("teplota :%3.1f",tep);
Provede se Vam inicializace displeje spravne?,
prosvitaji oba dva radky disp jako aktivni?
mozna bych zvysil cekaci doby pri posilani instrukci/dat displeji..
Mam rutinky v C napsane, pro osmibitove rizeni...
je to *.h file a da se nadefinovat (jednoduse) kam je disp pripojen.
Pokud budete mit zajem, muzu ho pslat na Vas soukromy mail.
Honza
----- Original Message -----
From: Jakub Ladman <ladmanj@volny.cz>
To: Multiple recipients of list <hw-news@list.gin.cz>
Sent: Tuesday, January 30, 2001 4:57 AM
Subject: EL1602B
> Nejak se tu marne snazim rozchodit LCD display viz. subj. s atmelem.
> Prosim, mate li nekdo cas, mrknete se na to proc to nechodi - treba Vas to
> trkne, ja uz tam nic nevidim.
>
> Nejsem na C zadny expert tak me nekamenujte.
>
> 1) soubor alphadisp.c
> /**********************
> *** main prasogram ***
> **********************/
>
> #include <C:\keil\c51\el1602b\hardware.c>
>
> void main()
> {
> unsigned char i;
> char code text[]="Ahoj vole, jak to jde. 01-2001 ";
> init();
> setadd(0);
> for (i=0; i<16; i++)
> {
> wrdat(text[i]);
> }
> setadd(0x40);
> for (i=0; i<16; i++)
> {
> wrdat(text[i]);
> }
> while(1) {}
> }
>
> 2) soubor hardware.c
> /***********************
> *** HARDWARE DRIVER ***
> ***********************/
>
> #include <c:\keil\c51\EL1602B\connect.h>
> #include <c:\keil\c51\inc\atmel\at89x51.h>
> #include <intrins.h>
>
> void strobe();
> void wrdat(unsigned char inbyte);
> unsigned char rddat();
> unsigned char rdac();
> unsigned char busy();
> void comnd(unsigned char inbyte);
> void clrdsp();
> void curhome();
> void entrymode(unsigned char I_D,S);
> void onoff(unsigned char D,C,B);
> void cur_shift(unsigned char S_C,R_L);
> void funcset(unsigned char DL,N,F);
> void set4bit (unsigned char byte);
> void init();
> void setacg(unsigned char ACG);
> void setadd(unsigned char ADD);
>
> unsigned char spodek(unsigned char inbyte);
> unsigned char vrsek(unsigned char inbyte);
> unsigned char spoj(unsigned char inlo,inhi);
>
> void set4bit(unsigned char byte) file://zapisuje inicializacni slova
> { file://pred nastavenim rozhrani
> P2 = P2 | 0xf;
> P2 = P2 & byte;
> R_W = 0;
> RS = 0;
> _nop_ ();
> _nop_ ();
> E = 0;
> _nop_ ();
> _nop_ ();
> _nop_ ();
> E = 1;
> }
> void init()
> {
> unsigned int i;
> for (i=0; i<10000; i++) {} // cekani pred prvnim zapisem (>15ms)
> set4bit(0xf3);
> for (i=0; i<5000; i++) {} // cekani po prvnim slovu (>4.1ms)
> set4bit(0xf3);
> for (i=0; i<100; i++) {} // cekani po druhem slovu (>100us)
> set4bit(0xf3);
> for (i=0; i<2000; i++) {} // cekani po tretim slovu (>1.5ms)
> set4bit(0xf2);
> funcset(0,1,0); // function set 0 0 0 0 DL N F
> onoff(1,1,1); // display ON/OFF control 0 0 0 0 0 0 0 D C B
> clrdsp(); // Clear display 0 0 0 0 0 0 0 0 0 1
> curhome(); // cursor at home 0 0 0 0 0 0 0 0 1 -
> entrymode(1,0); // entry mod set 0 0 0 0 0 0 0 0 I/D S
> }
>
> void wrdat(unsigned char inbyte)
> {
> while (busy()) {}
> P2 = P2 | 0xf; file://nastavit low nible na 1111
> P2 = P2 & vrsek(inbyte); file://beze zmeny ridicich bitu zapsat na P2
horni cast
> dat
> RS = 1; file://nastavit RAM SELECT - budeme pracovat s daty
> R_W = 0; file://nastavit WRITE - budeme zapisovat
> _nop_ (); file://pockame na display min 40 ns
> _nop_ ();
> E = 0; file://sestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame na display min 220 ns
> _nop_ ();
> _nop_ ();
> E = 1; file://vzestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> P2 = P2 | 0xf; file://nastavit low nible na 1111
> P2 = P2 & spodek(inbyte); file://beze zmeny ridicich bitu zapsat na P2
dolni
> cast dat
> _nop_ (); file://pockame
> _nop_ ();
> E = 0; file://sestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame na display min 220 ns
> _nop_ ();
> _nop_ ();
> E =1 ; file://vzestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> RS = 0; file://RAM SELECT do vychozi polohy
> }
> unsigned char rddat()
> {
> unsigned char tmp1,tmp2;
> while (busy()) {}
> RS = 1; file://nastavit RAM SELECT - budeme pracovat s daty
> R_W = 1; file://nastavit READ - budeme cist
> _nop_ (); file://pockame na display min 40 ns
> _nop_ ();
> E = 0; file://sestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame na display min 220 ns
> _nop_ ();
> _nop_ ();
> tmp1 = P2;
> E = 1; file://vzestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> E = 0; file://sestupna hrana strobe
> _nop_ (); // 220 ns
> _nop_ ();
> _nop_ ();
> tmp2 = P2;
> E = 1; file://vzestupna hrana strobe
> _nop_ (); // 220 ns
> _nop_ ();
> _nop_ ();
> RS = 0; file://RAM SELECT do vychozi polohy
> R_W = 0; file://R_W taky
> return spoj(tmp2,tmp1);
> }
> unsigned char rdac()
> {
> unsigned char tmp1,tmp2;
> while (busy()) {}
> RS = 0; file://nulovat RAM SELECT
> R_W = 1; file://nastavit READ - budeme cist
> _nop_ (); file://pockame na display min 40 ns
> _nop_ ();
> E = 0; file://sestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame na display min 220 ns
> _nop_ ();
> _nop_ ();
> tmp1 = P2;
> E = 1; file://vzestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> E = 0; file://sestupna hrana strobe
> _nop_ (); // 220 ns
> _nop_ ();
> _nop_ ();
> tmp2 = P2;
> E = 1; file://vzestupna hrana strobe
> _nop_ (); // 220 ns
> _nop_ ();
> _nop_ ();
> R_W = 0; file://R_W do vychozi polohy
> return (spoj(tmp2,tmp1) & 0x7f);
> }
> unsigned char busy()
> {
> unsigned char out;
> RS = 0;
> R_W = 1;
> _nop_ ();
> _nop_ ();
> E = 0;
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> out = DB7; file://cte busy flag
> E = 1;
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> E = 0;
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> E = 1;
> RS = 0;
> R_W = 0;
> return out;
> }
> void comnd(unsigned char inbyte)
> {
> while (busy()) {}
> P2 = P2 | 0xf; file://nastavit low nible na 1111
> P2 = P2 & vrsek(inbyte); file://beze zmeny ridicich bitu zapsat na P2
horni cast
> dat
> RS = 0; file://nulovat RAM SELECT
> R_W = 0; file://nastavit WRITE - budeme zapisovat
> _nop_ (); file://pockame na display min 40 ns
> _nop_ ();
> E = 0; file://sestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame na display min 220 ns
> _nop_ ();
> _nop_ ();
> E = 1; file://vzestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> P2 = P2 | 0xf; file://nastavit low nible na 1111
> P2 = P2 & spodek(inbyte); file://beze zmeny ridicich bitu zapsat na P2
dolni
> cast dat
> _nop_ (); file://pockame
> _nop_ ();
> E = 0; file://sestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame na display min 220 ns
> _nop_ ();
> _nop_ ();
> E = 1; file://vzestupna hrana strobovaciho vstupu
> _nop_ (); file://pockame 220 ns
> _nop_ ();
> _nop_ ();
> }
> void clrdsp()
> {
> comnd(0x1);
> }
> void curhome()
> {
> comnd(0x2);
> }
> void entrymode(unsigned char I_D,S)
> {
> comnd(4+2*I_D+S);
> }
> void onoff(unsigned char D,C,B)
> {
> comnd(8+4*D+2*C+B);
> }
> void cur_shift(unsigned char S_C,R_L)
> {
> comnd(16+8*S_C+4*R_L);
> }
> void funcset(unsigned char DL,N,F)
> {
> comnd(32+16*DL+8*N+4*F);
> }
> void setacg(unsigned char ACG)
> {
> comnd(64+ACG);
> }
> void setadd(unsigned char ADD)
> {
> comnd(128+ADD);
> }
> unsigned char spodek(unsigned char inbyte) file://vytahne z bytu low
nibble
> { // ... takhle: 1 1 1 1 D3 D2 D1 D0
> unsigned char out;
> out = 0xf0 | inbyte;
> return out;
> }
> unsigned char vrsek(unsigned char inbyte) file://vytahne z bytu high
nibble
> { // ... takhle: 1 1 1 1 D7 D6 D5 D4
> unsigned char out;
> inbyte = inbyte >> 4;
> out = 0xf0 | inbyte;
> return out;
> }
> unsigned char spoj(unsigned char inlo,inhi) // spojí low a high nibble do
> jednoho
> { // bytu
> unsigned char out;
> inlo = inlo | 0xf0;
> inhi = inhi << 4;
> inhi = inhi | 0xf;
> out = inhi & inlo;
> return out;
> }
>
> 3) soubor connect.h
> /***********************************
> *** definice připojení displaye ***
> ***********************************/
> sbit DB4 = 0xA0; // nejnižší bit čtyřbitového slova
> sbit DB5 = 0xA1;
> sbit DB6 = 0xA2;
> sbit DB7 = 0xA3; // nejvyšší ...
> sbit E = 0xA4; // Enable (strobe) bit - reaguje na -_
> sbit R_W = 0xA5; // - = read _ = write
> sbit RS = 0xA6; // - = ram _ = other
> sbit LED = 0xA7; // back light - spínání ledky podsvícení
>
>
> Diky za pomoc
> Jakub Ladman
>
Další informace o konferenci Hw-list