Jump to content
ELFORUM - Forumul electronistilor

interfete si comunicatii


laStudiu

Recommended Posts

  • Replies 98
  • Created
  • Last Reply

Am gasit un driver pt LCD, dar i-mi da eroarea in PICC-Lite:

(107) illegal # directive "byte" ... la codul

#byte lcd = 8 // on to port D (at address 8)

PICC-Lite e compilator de C, iar codul ala nu pare a fi pentru C, in C cu # incep directivele preprocesor (#define, #include, #pragma, etc). Nici byte nu e vreun tip standard de variabila in C (ar fi trebuit unsigned char).

 

LE: vezi aici niste cod pt. LCD (si alte interfete) pentru PICC: http://www.microchipc.com/sourcecode

Link to comment
Share on other sites

Am cumparat un (LCD) LCM16011A-TGR de la Capodimonte (16 caractere x 1 linie) si are 16 pini si vreau sa stiu daca pinii 15, 16 (A, respectiv K) trebuie legati la montaj ? ... (i-am lasat in aer) ... ca nu merge afisajul si vreau sa stiu daca nu-i o problema hard ... pentru cine are nervi atasez softul impreuna cu driverele care le-am gasit in ProgramFiles\ Microchip\.. \Drivers pe care le-am modificat pentru portul D (am facut eu rutinele delay, bit_test() ... le-am rasucit, invartit si m-am obosit :smt001

Link to comment
Share on other sites

Am cumparat un (LCD) LCM16011A-TGR de la Capodimonte (16 caractere x 1 linie) si are 16 pini si vreau sa stiu daca pinii 15, 16 (A, respectiv K) trebuie legati la montaj ? ... (i-am lasat in aer) ... ca nu merge afisajul si vreau sa stiu daca nu-i o problema hard ... pentru cine are nervi atasez softul impreuna cu driverele care le-am gasit in ProgramFiles\ Microchip\.. \Drivers pe care le-am modificat pentru portul D (am facut eu rutinele delay, bit_test() ... le-am rasucit, invartit si m-am obosit :smt001

Pinii A si K sunt pentru backlight, montajul trebuie sa mearga si fara (presupunand ca restul pinilor sunt corect conectati). Pune schema si codul aici, ca sa vedem ce nu e in regula.
Link to comment
Share on other sites

Nu reusesc sa atasez .zip (cica-i prea mare). Deci iata driverul:ProgramFiles/ Microchip/ ThirdParty/PICC /Drivers/LCD420.c

// 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 2           // 0=5x7, 1=5x10, 2=2 linesBYTE 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 inBYTE 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=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);}
Link to comment
Share on other sites

Si acum ce am facut eu :

// As defined in the following structure the pin connection is as follows://     D0  enable//     D1  rs//     D2  rw//     D4  D4//     D5  D5//     D6  D6//     D7  D7////   LCD pins D0-D3 are not used and PIC D3 is not used.#include<htc.h>#include "delay_LCD.h"int bit_test(unsigned char c, unsigned char i){	return c & (1 << i);}					struct lcd_pin_map {                 // This structure is overlayed           unsigned enable : 1;           // on to an I/O port to gain           unsigned rs : 1;               // access to the LCD pins.           unsigned rw : 1;               // The bits are allocated from           unsigned unused : 1;           // low order up.  ENABLE will           unsigned int  data : 4;        	 // be pin D0.                   } lcd @ 0x08;                      // This puts the entire structure                                   		  // on to port D (at address 8)#define lcd_type 1           // 0=5x7, 1=5x10, 2=2 linesunsigned char 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 inunsigned char lcdline;void set_tris_d(struct lcd_pin_map Direction){	unsigned int dir = 0 | Direction.data;	TRISD = dir;}unsigned char lcd_read_byte(void) {      unsigned char low,high;      set_tris_d(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_d(LCD_WRITE);      return( (high<<4) | low);}void lcd_send_nibble( unsigned char n ) {      lcd.data = n;      delay_cycles(1);      lcd.enable = 1;      delay_us(2);      lcd.enable = 0;}void lcd_send_byte( unsigned char address, unsigned char 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(void) {    unsigned char i;    set_tris_d(LCD_WRITE);    lcd.rs = 0;    delay_ms(15);    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);    delay_ms(5);    for(i=0;i<=3;++i)       lcd_send_byte(0, LCD_INIT_STRING[i]);    delay_ms(1);}void lcd_gotox( unsigned char x){   unsigned char address;  	address = 0x80;         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 '\b'   : lcd_send_byte(0,0x10);  break;     default     : lcd_send_byte(1,c);     break;   }}char lcd_getc( unsigned char x) {   char value;    lcd_gotox(x);    lcd.rs=1;    value = lcd_read_byte();    lcd.rs=0;    return(value);}
Link to comment
Share on other sites

Si delayLCD.c :

#include<htc.h>void delay_cycles(int n){ 	while(n--)	{			#asm			nop;		#endasm	}}void delay_us(int n)	//5 * 200 ns{ 	while(n--)	{			#asm			nop;			nop;			nop;			nop;			nop;		#endasm	}}void delay_ms(int n){ 	int i = 4 * 995;	while(n--)	{	while(i--)			continue;		i = 4 * 995;	}}
Link to comment
Share on other sites

Orice depanare incepe cu schema, cauta alte solutii pentru a o pune aici.

 

Legat de software: rutinele alea nu sunt pentru HiTech C, nu exista tipul BOOLEAN in C, nici tipul BYTE (decat daca ar fi definite cu un typedef, dar nu vad sa fie), nu exista directiva #byte. Codul de acolo nu e ANSI C si trebuie modificat un pic (foloseste unsigned char in loc de BYTE, bit in loc de BOOLEAN, #define LCD=PORTB in loc de #byte lcd=6). Apoi, rutinele de delay nu sunt bune, vor rezulta alti timpi decat te astepti (trebuie sa te gandesti cum se "traduce" codul in C in instructiuni de PIC si trebuie sa mai tii cont si de subtilitatile din C: while(i--) nu va fi transpus in decfsz i, label - te las sa-mi spui tu de ce, plus ca bucla necesita si instructiune de salt inapoi - inca 2 cicli, in plus fata de nop). Codul in sine nu stiu sigur daca functioneaza (n-am compilator in cap :yawinkle: ), totusi pare a fi ok. Dupa ce faci modificarile necesare si programul va fi compilat, mai discutam.

Link to comment
Share on other sites

Guest Vasile

Nu pot sa pun schema. Cica: "Sorry, but the maximum filesize for all Attachments is reached."[/img]

iti zice ezact ce dimensiune poti sa pui deci optimizeaz-o redimensioneaz-o... etc ca doar nu trebuie sa fie la rezolutie de pozna artistica :smt003
Link to comment
Share on other sites

De ce in schema LCD-ul e conectat la portul D iar in softul e scris ca si cum LCD-ul ar fi conectat la portul B ?

Softul care l-am gasit foloseste portul B (l-am pus asa cum e). Eu am modificat softul pentru portul D (care l-am pus a 2-lea) ... nu stiu ce ar trebui sa faca functia bit_test() din lcd_send_byte()
Link to comment
Share on other sites

Codul ala pare cam varza la o prima privire. Se apeleaza functia set_tris_b, dar la numele functiei ai modificat set_tris_d. Codul nu e scris in stil PICC, deci vei avea putintel de modificat la el pana sa-l faci sa mearga.

 

La schema ai inversat RS cu R/W din cod.

 

Iti recomand sa arunci un ochi si pe codul de aici:

http://www.htsoft.com/forum/all/showfla ... #Post19680

 

S-ar putea sa mearga adaptat mai usor.

 

Succes !

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.




×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines