Sari la conținut
ELFORUM - Forumul electronistilor

Intrebare 16F887 - compatibilitate LCD...


pyu

Postări Recomandate

Cu partea de hard am inteles, voi reface diseara, cand ies de la servici :)

2. partea de soft:C18 iti pune la dispozitie o interfata catre LCD, numita xlcd.

Dar eu nu pot folosi C18 compiler... Folosesc pic 16F887, iar C18 are suport doar pentru Pic 18F, cel putin asa am gasit.Eu folosesc MPLAB si CCS C compiler.
Link spre comentariu
  • Răspunsuri 31
  • Creat
  • Ultimul Răspuns

Top autori în acest subiect

  • pyu

    19

  • kit

    5

  • soulraven

    3

  • crispus

    2

Top autori în acest subiect

Nu are cineva un program in C, care sa afiseze ceva pe un lcd (8 bit interface)?Am gasit eu ceva pe net, dar nu inteleg nimic din ce e acolo, nu era nimic concret.

asta a fost tare! parerea mea este ca n-o sa-mi ajunga o viata ca sa citesc toata documentatia la obiect pe care o gasesti pe net cu pivire la subiectul asta.
Sunt programator ASP.NET. Nu prea e de domeniul meu programarea microcontrolerelor, sau mai ales LCD-urile :)Sunt lucruri care nu le inteleg atat de usor. Si din pacate timpul meu este foarte limitat, nu am cum sa rascolesc toate informatiile care le gasesc pe prietenul nostru google, mai ales sa le pun in practica.Sper ca ma intelegi...
Link spre comentariu
Sper ca ma intelegi...

oh, da, te inteleg perfect!

Sunt programator ASP.NET

fain! dar nu se pupa deloc cu picurile, din pacate.

Dar eu nu pot folosi C18 compiler... Folosesc pic 16F887, iar C18 are suport doar pentru Pic 18F, cel putin asa am gasit.

Eu folosesc MPLAB si CCS C compiler.

scuze, am fost cascat. totusi, CSS C nu are ceva bilblioteci in sensul asta?

in directorul "DRIVERS" nu sunt fisierele:

LCD.C LCD module functions (for a 2x16 display)

LCD420.C LCD module functions (for a 4x20 display) ?

Am luat informatiile de aici: http://www.ccsinfo.com/devices.php?page=exlist

daca exista atunci trebuie sa fie si headerele "*.h", pe care ar trebui sa le modifici, probabil, cu pinii folositi in aplicatie.

Sper sa te ajute, bafta!

Link spre comentariu

Am facut niste teste, din pacate, rezultatul a fost un esec, nu s-a afisat nimic pe display, singurul lucru care se vede este o usoara "colorare" a liniei a 2-a si a 4-a.

 

Conexiunile:

// LCD pin connection is as follows:

// 1 - Vss - Ground

// 2 - Vdd - +5V

// 3 - Vo - 20K pot

// 4 - RS - RB1

// 5 - RW - RB2

// 6 - E - RB3

// 7 - DB0 - RC0

// 8 - DB1 - RC1

// 9 - DB2 - RC2

// 10 - DB3 - RC3

// 11 - DB4 - RC4

// 12 - DB5 - RC5

// 13 - DB6 - RC6

// 14 - DB7 - RC7

// 15 - A - N/C

// 16 - K - N/C

//

 

 

sisierul Test_lcd.c:

#include <16F887.h>             // header file for the PIC16F887                                // includes built-in functions and constants                                // for arguments/returns.#include <math.h>#include <stdio.h>//#use fast_io(A)                 // all other ports default to 'standard_io'//#use fast_io(B)                 // fast_io means the tris bits only change                                // when we explicitly set them.// FUSES sets the PIC16F887 Configuration Words.  See top of the header file// 16F887.h for fuse option constants.#FUSES INTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP#use delay (clock=20000000)#include <lcd420.c>void main(){	//init LCD	lcd_init();	//put char	lcd_putc("\fReady...\n");}  

si fisierul lcd240.c:

//// compiler.  This source code may only be distributed to other       //////// licensed users of the CCS C compiler.  No other use, reproduction  //////// or distribution is permitted without written permission.           //////// Derivative programs created using this software in object code     //////// form are not restricted in any way.                                ////////////////////////////////////////////////////////////////////////////////// As defined in the following structure the pin connection is as follows://     B0  enable//     B1  rs//     B2  rw//     B4  D4//     B5  D5//     B6  D6//     B7  D7////   LCD pins D0-D3 are not used and PIC B3 is not used.struct lcd_pin_map {                 // This structure is overlayed           BOOLEAN enable;           // on to an I/O port to gain           BOOLEAN rs;               // access to the LCD pins.           BOOLEAN rw;               // The bits are allocated from           BOOLEAN unused;           // low order up.  ENABLE will           int     data : 4;         // be pin B0.        } lcd;#byte lcd = 6                        // This puts the entire structure                                     // on to port B (at address 6)//#define LCD_TYPE       1      // 2x16 LCD//#define LCD_TYPE       2      // 2x20 LCD//#define LCD_TYPE       3      // 2x24 LCD//#define LCD_TYPE       4      // 2x40 LCD//#define LCD_TYPE       5      // 4x16 LCD//#define LCD_TYPE       6      // 4x20 LCD//#define LCD_TYPE       7      // Graphisc LCD Nokia #define lcd_type 6//#define lcd_line_one 0x00    // LCD RAM address for the second line//#define lcd_line_two 0x40    // LCD RAM address for the second line//#define lcd_line_three 0x14    // LCD RAM address for the second line//#define lcd_line_four 0x54    // LCD RAM address for the second line// These bytes need to be sent to the LCD// to start it up.BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 			// Func set: 4-bit, 2 lines, 5x8 dots0xc, 								// Display on1, 									// Clear display6									// Increment cursor};                            // The following are used for setting// the I/O port direction register.struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are outstruct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are inBYTE lcdline;BYTE lcd_read_byte() {      BYTE low,high;      set_tris_c(LCD_READ);      lcd.rw = 1;      delay_cycles(1);      lcd.enable = 1;      delay_cycles(1);      high = lcd.data;      lcd.enable = 0;      delay_cycles(1);      lcd.enable = 1;      delay_us(1);      low = lcd.data;      lcd.enable = 0;      set_tris_c(LCD_WRITE);      return( (high<<4) | low);}void lcd_send_nibble( BYTE n ) {      lcd.data = n;      delay_cycles(1);      lcd.enable = 1;      delay_us(2);      lcd.enable = 0;}void lcd_send_byte( BYTE address, BYTE n ) {      lcd.rs = 0;      while ( bit_test(lcd_read_byte(),7) ) ;      lcd.rs = address;      delay_cycles(1);      lcd.rw = 0;      delay_cycles(1);      lcd.enable = 0;      lcd_send_nibble(n >> 4);      lcd_send_nibble(n & 0xf);}void lcd_init() {    BYTE i;    set_tris_c(LCD_WRITE);    lcd.rs = 0;    lcd.rw = 0;    lcd.enable = 0;    delay_ms(15);    for(i=1;i<=3;++i) {       lcd_send_nibble(3);       delay_ms(5);    }    lcd_send_nibble(2);    for(i=0;i<=3;++i)       lcd_send_byte(0, LCD_INIT_STRING[i]);}void lcd_gotoxy( BYTE x, BYTE y) {   BYTE address;   switch(y) {     case 1 : address=0x80;break;     case 2 : address=0xc0;break;     case 3 : address=0x94;break;     case 4 : address=0xd4;break;   }   address+=x-1;   lcd_send_byte(0,address);}void lcd_putc( char c) {   switch (c) {     case '\f'   : lcd_send_byte(0,1);                   lcdline=1;                   delay_ms(2);                                           break;     case '\n'   : lcd_gotoxy(1,++lcdline);        break;     case '\b'   : lcd_send_byte(0,0x10);  break;     default     : lcd_send_byte(1,c);     break;   }}char lcd_getc( BYTE x, BYTE y) {   char value;    lcd_gotoxy(x,y);    lcd.rs=1;    value = lcd_read_byte();    lcd.rs=0;    return(value);}

Ma poate ajuta cineva sa corectez ?

Link spre comentariu

nu lucrez in CCS dar uite ce vad eu

 

// lcd-ul foloseste doar pini D4-D7 si EN,RS,RW si RB3 nu este folosit

// As defined in the following structure the pin connection is as follows://     B0  enable//     B1  rs//     B2  rw//     B4  D4//     B5  D5//     B6  D6//     B7  D7////   LCD pins D0-D3 are not used and PIC B3 is not used.
// aici vad ca foloseste PORTB ptr comunicarea cu LCD

#byte lcd = 6                        // This puts the entire structure                                      // on to port B (at address 6)
deci LCD-ul trebuie conectat la PORTB, sau poti modifica tu ptr cum ai conectat LCD-ul
Link spre comentariu

// lcd-ul foloseste doar pini D4-D7 si EN,RS,RW si RB3 nu este folosit

Da, asa era initial, eu nu vreau sa folosesc pinii aia, am uitat sa sterg comentariile alea.

// aici vad ca foloseste PORTB ptr comunicarea cu LCD

#byte lcd = 6                        // This puts the entire structure                                      // on to port B (at address 6)
deci LCD-ul trebuie conectat la PORTB, sau poti modifica tu ptr cum ai conectat LCD-ul
Deci 6 este pentru portul B... Si pentru portul C, ce trebuie folosit? De unde ia el cifra aia?
Link spre comentariu

atat? fisierul lcd420.h (sau orice *lcd*.h) nu exista? pentru ca acolo ar trebui sa fie definitiile. in plus, *.h ar trebui indicat in directiva #include si nu fisierul sursa *.ccel putin asa am eu in C18 si in orice alt mediu C cu care am lucrat...daca exista acel header, treaba-i simpla, se editeaza. sub C18 headerele sunt in directorul ..\h, de acolo le-am preluat si editat si eu.oricum, e sigur, LCD-ul ala nu-i initializat bine (asta am invatat-o de pe forum :aplauze, cand am patit si eu la fel)

Link spre comentariu

nu exista o astfel de librarie (.h), ci doar .c.

 

Am dat search pe tot hdd-ul, si am gasit

XLCD.H (dar este pentru alt compilator):

* FileName:        XLCD.h * Dependencies:    compiler.h * Processor:       PIC18 * Complier:        MCC18 v1.00.50 or higher *                  HITECH PICC-18 V8.10PL1 or higher * Company:         Microchip Technology, Inc. *

XLCD.INC (dar este cod asm in el)

;* FileName:            XLCD.inc	;* Dependencies:        P16xxx.inc	;*                      XLCD.Def	;* Processor:           PIC16xxxx	;* Assembler:           MPASMWIN 02.70.02 or higher;* Linker:              MPLINK 2.33.00 or higher;* Company:             Microchip Technology, Inc.

XLCD.Def - l-am cautat pe tot hardul, nu este asemenea fisier.

 

Recomandati-mi un alt compilator, daca nu se poate cu acesta... Exclus ASM :)

Link spre comentariu

cifra aia o ia din pdf-ul pic-ului la "Memory Organization" sunt niste tabele cu adresele porturilor(etc.)

da, am gasit pana la urma :) 06h - B, 07h - C, dar deocamdata nu ma ajuta, pt ca nu merge restul programului :|L.E.: Am observat ceva ciudat atunci cand fac debugging...Ajunge la void lcd_init(), face totul pana la delay_ms(15); - > cursorul se duce pe #use delay (clock=20000000), si nu mai termina niciodata executia (sau ce face el), nu sare niciodata la urmatorul breakpoint dupa delay_ms(15); . Care ar fi explicatia?
Link spre comentariu

Am refacut conexiunile, exact cum erau in fisiserul LCD420.c

 

main.c

#include <16F887.h>             // header file for the PIC16F887                                // includes built-in functions and constants                                // for arguments/returns.#include <math.h>#include <stdio.h>// FUSES sets the PIC16F887 Configuration Words.  See top of the header file// 16F887.h for fuse option constants.#FUSES INTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP#use delay (clock=4000000)#include <lcd420.c>void main(){	//init LCD	lcd_init();	//put char	lcd_putc("\fReady...\n");}  

lcd420.c:

////////////////////////////////////////////////////////////////////////////////                             LCD420.C                               ////////            Driver for common 4x20 LCD modules                      ////////                                                                    ////////  lcd_init()   Must be called before any other function.            ////////                                                                    ////////  lcd_putc(c)  Will display c on the next position of the LCD.      ////////                     The following have special meaning:            ////////                      \f  Clear display                             ////////                      \n  Go to start of second line                ////////                      \b  Move back one position                    ////////                                                                    ////////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)     ////////                                                                    ////////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////////                                                                    ////////////////////////////////////////////////////////////////////////////////////        (C) Copyright 1996,1997 Custom Computer Services            //////// This source code may only be used by licensed users of the CCS C   //////// compiler.  This source code may only be distributed to other       //////// licensed users of the CCS C compiler.  No other use, reproduction  //////// or distribution is permitted without written permission.           //////// Derivative programs created using this software in object code     //////// form are not restricted in any way.                                ////////////////////////////////////////////////////////////////////////////////// As defined in the following structure the pin connection is as follows://     B0  enable//     B1  rs//     B2  rw//     B4  D4//     B5  D5//     B6  D6//     B7  D7////   LCD pins D0-D3 are not used and PIC B3 is not used.struct lcd_pin_map {                 // This structure is overlayed           BOOLEAN enable;           // on to an I/O port to gain           BOOLEAN rs;               // access to the LCD pins.           BOOLEAN rw;               // The bits are allocated from           BOOLEAN unused;           // low order up.  ENABLE will           int     data : 4;         // be pin B0.        } lcd;#byte lcd = 6                        // This puts the entire structure                                     // on to port B (at address 6)#define lcd_type 6           // 0=5x7, 1=5x10, 2=2 lines		          //6 - 4x20 LCDBYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};                             // These bytes need to be sent to the LCD                             // to start it up.                             // The following are used for setting                             // the I/O port direction register.struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are outstruct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in// Address positions #define LCD_LINE_1 0x00 // Position of start of line 1 #define LCD_LINE_2 0x40 // Position of start of line 2 #define LCD_LINE_3 0x14 // Position of start of line 3 #define LCD_LINE_4 0x54 // Position of start of line 4 BYTE lcdline;BYTE lcd_read_byte() {      BYTE low,high;      set_tris_b(LCD_READ);      lcd.rw = 1;      delay_cycles(1);      lcd.enable = 1;      delay_cycles(1);      high = lcd.data;      lcd.enable = 0;      delay_cycles(1);      lcd.enable = 1;      delay_us(1);      low = lcd.data;      lcd.enable = 0;      set_tris_b(LCD_WRITE);      return( (high<<4) | low);}void lcd_send_nibble( BYTE n ) {      lcd.data = n;      delay_cycles(1);      lcd.enable = 1;      delay_us(2);      lcd.enable = 0;}void lcd_send_byte( BYTE address, BYTE n ) {      lcd.rs = 0;      while ( bit_test(lcd_read_byte(),7) ) ;      lcd.rs = address;      delay_cycles(1);      lcd.rw = 0;      delay_cycles(1);      lcd.enable = 0;      lcd_send_nibble(n >> 4);      lcd_send_nibble(n & 0xf);}void lcd_init() {    BYTE i;    set_tris_b(LCD_WRITE);    lcd.rs = 0;    lcd.rw = 0;    lcd.enable = 0;    delay_ms(15);    for(i=1;i<=3;++i) {       lcd_send_nibble(3);       delay_ms(5);    }    lcd_send_nibble(2);    for(i=0;i<=3;++i)       lcd_send_byte(0, LCD_INIT_STRING[i]);}void lcd_gotoxy( BYTE x, BYTE y) {   BYTE address;   switch(y) {     case 1 : address=LCD_LINE_1;break;     case 2 : address=LCD_LINE_2;break;     case 3 : address=LCD_LINE_1;break;     case 4 : address=LCD_LINE_1;break;   }   address+=x-1;   lcd_send_byte(0,address);}void lcd_putc( char c) {   switch (c) {     case '\f'   : lcd_send_byte(0,1);                   lcdline=1;                   delay_ms(2);                                           break;     case '\n'   : lcd_gotoxy(1,++lcdline);        break;     case '\b'   : lcd_send_byte(0,0x10);  break;     default     : lcd_send_byte(1,c);     break;   }}char lcd_getc( BYTE x, BYTE y) {   char value;    lcd_gotoxy(x,y);    lcd.rs=1;    value = lcd_read_byte();    lcd.rs=0;    return(value);}
Nu merge nici asa... Chiar nu stie nimeni de ce?
Link spre comentariu

Da, am reusit...Pentru cei interesati, spune-ti si va pot da codul. Problema era ca pickit2 foloseste pentru debuggind niste pini ai portului B.Am folosit Flex_LCD.c (by PCM programmer), cu mici modificari (porturile folosite), care chiar merge, cel care l-a facut stie el ce stie, el m-a ajutat sa rezolv problema.

Link spre comentariu

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum



×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări