Jump to content
ELFORUM - Forumul electronistilor

LCD 2x16 + 16f628a


pspsuceava
 Share

Recommended Posts

IDE : MPLAB

COMPILATOR : XC8

Nu exista exemple pentru acest compilator de lcd facute ok... Eu nu am gasit.

 

M-am chinuit sa adaptez diverse programe pentru alte compilatoare dar nu am reusit...

 

Ce am reusit pana acum:

 

#include <xc.h>//#include <htc.h>#pragma config BOREN = OFF, CPD = OFF, FOSC = XT , MCLRE = OFF, WDTE = OFF, CP = OFF, LVP = OFF, PWRTE = ON#define _XTAL_FREQ = 4000000#define	LCD_RS RB6#define	LCD_RW RB5#define LCD_EN RB4#define LCD_DATA	PORTB#define	LCD_STROBE()	((LCD_EN = 1),(LCD_EN=0))/* write a byte to the LCD in 4 bit mode */void delay_ms(unsigned int n){	do {		_delay(4000);	} while(--n != 0);}void delay_us(unsigned int i){    do {		_delay(4);	} while(--i != 0);voidlcd_write(unsigned char c){	DelayUs(40);	LCD_DATA = ( ( c >> 4 ) & 0x0F );	LCD_STROBE();	LCD_DATA = ( c & 0x0F );	LCD_STROBE();}/* * 	Clear and home the LCD */voidlcd_clear(void){	LCD_RS = 0;	lcd_write(0x1);	DelayMs(2);}/* write a string of chars to the LCD */voidlcd_puts(const char * s){	LCD_RS = 1;	// write characters	while(*s)		lcd_write(*s++);}/* write one character to the LCD */voidlcd_putch(char c){	LCD_RS = 1;	// write characters	lcd_write( c );}/* * Go to the specified position */voidlcd_goto(unsigned char pos){	LCD_RS = 0;	lcd_write(0x80+pos);}/* initialise the LCD - put into 4 bit mode */voidlcd_init(){	char init_value;	//COMPARATORIII	init_value = 0x3;	//TRISA=0;	TRISB=0b00000000;	LCD_RS = 0;	LCD_EN = 0;	LCD_RW = 0;	DelayMs(15);	// wait 15mSec after power applied,	LCD_DATA	 = init_value;	LCD_STROBE();	DelayMs(5);	LCD_STROBE();	DelayUs(200);	LCD_STROBE();	DelayUs(200);	LCD_DATA = 2;	// Four bit mode	LCD_STROBE();	lcd_write(0x28); // Set interface length	lcd_write(0xF); // Display On, Cursor On, Cursor Blink	lcd_clear();	// Clear screen	lcd_write(0x6); // Set entry Mode}void main(){	lcd_init();        lcd_goto(0);	// select first line	lcd_puts("12345678");	lcd_goto(0x40);	// Select second line	lcd_puts("Hello world");	for(;;);}

Vedeti vreo greseala?

Ce cred eu ca este gresit, probabil routinele de delay...

Link to comment
Share on other sites

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

#define	LCD_RS RB6#define	LCD_RW RB5#define LCD_EN RB4#define LCD_DATA	PORTB...lcd_write(unsigned char c){   DelayUs(40);   LCD_DATA = ( ( c >> 4 ) & 0x0F );...
Cand faci LCD_DATA = ( ( c >> 4 ) & 0x0F ); faci RB4..RB6 = 0. In cazul asta, RS=1 din puts e inutil, primul lcd_write il face 0:
lcd_puts(const char * s){   LCD_RS = 1;   // write characters   while(*s)      lcd_write(*s++);}
Pe de alta parte, in xc8 exista _delay_ms() si _delay_us(), nu-s convins ca-ti trebuie functii proprii.
Link to comment
Share on other sites

Daca c=0xab, rezultatul operatiei:

LCD_DATA = ( ( c >> 4 ) & 0x0F );
e echivalent cu

PORTB = 0x0a
Cu alte cuvinte, RB7..RB4 = 0b0000. Cu alte cuvinte, dupa o operatie lcd_write, obtii RB6 == LCD_RS = 0.

 

Referitor la _delay_us()/_delay_ms() care e mesajul de eroare?

Link to comment
Share on other sites

Referitor la delay:Cand folosesc delayms() simplu:make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-confmake[1]: Entering directory `C:/Users/Iliescu/MPLABXProjects/LCDTESTv2.X'make -f nbproject/Makefile-default.mk dist/default/production/LCDTESTv2.X.production.hexmake[2]: Entering directory `C:/Users/Iliescu/MPLABXProjects/LCDTESTv2.X'"G:\MPLAB\Microchip\xc8\v1.30\bin\xc8.exe" --pass1 --chip=16F628A -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -obuild/default/production/lcd.p1 lcd.c lcd.c:36: warning: (361) function declared implicit intlcd.c:90: warning: (361) function declared implicit int"G:\MPLAB\Microchip\xc8\v1.30\bin\xc8.exe" --chip=16F628A -G -mdist/default/production/LCDTESTv2.X.production.map --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/default/production/LCDTESTv2.X.production.elf build/default/production/lcd.p1 Microchip MPLAB XC8 C Compiler (Free Mode) V1.30Copyright © 2014 Microchip Technology Inc.License type: Node Configuration:: warning: (1273) Omniscient Code Generation not available in Free modelcd.c:36: warning: (1464) number of arguments passed to function "_DelayMs" does not match function's prototypelcd.c:85: warning: (1464) number of arguments passed to function "_DelayMs" does not match function's prototypelcd.c:88: warning: (1464) number of arguments passed to function "_DelayMs" does not match function's prototypelcd.c:90: warning: (1464) number of arguments passed to function "_DelayUs" does not match function's prototypelcd.c:92: warning: (1464) number of arguments passed to function "_DelayUs" does not match function's prototype:0: error: undefined symbols: _DelayMs(dist/default/production\LCDTESTv2.X.production.obj) _DelayUs(dist/default/production\LCDTESTv2.X.production.obj) (908) exit status = 1make[2]: *** [dist/default/production/LCDTESTv2.X.production.hex] Error 1make[1]: *** [.build-conf] Error 2make: *** [.build-impl] Error 2make[2]: Leaving directory `C:/Users/Iliescu/MPLABXProjects/LCDTESTv2.X'make[1]: Leaving directory `C:/Users/Iliescu/MPLABXProjects/LCDTESTv2.X'BUILD FAILED (exit value 2, total time: 3s)cand folosesc _delay_ms(); cum ai zis tu:make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-confmake[1]: Entering directory `C:/Users/Iliescu/MPLABXProjects/STERGE.X'make -f nbproject/Makefile-default.mk dist/default/production/STERGE.X.production.hexmake[2]: Entering directory `C:/Users/Iliescu/MPLABXProjects/STERGE.X'"G:\MPLAB\Microchip\xc8\v1.30\bin\xc8.exe" --pass1 --chip=16F628A -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -obuild/default/production/newmain.p1 newmain.c newmain.c:22: warning: (361) function declared implicit intnewmain.c:38: warning: (361) function declared implicit int"G:\MPLAB\Microchip\xc8\v1.30\bin\xc8.exe" --chip=16F628A -G -mdist/default/production/STERGE.X.production.map --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s" -odist/default/production/STERGE.X.production.elf build/default/production/newmain.p1 Microchip MPLAB XC8 C Compiler (Free Mode) V1.30Copyright © 2014 Microchip Technology Inc.License type: Node Configuration:: warning: (1273) Omniscient Code Generation not available in Free modenewmain.c:38: warning: (1464) number of arguments passed to function "__delay_ms" does not match function's prototypenewmain.c:87: warning: (1464) number of arguments passed to function "__delay_ms" does not match function's prototypenewmain.c:90: warning: (1464) number of arguments passed to function "__delay_ms" does not match function's prototypenewmain.c:92: warning: (1464) number of arguments passed to function "__delay_us" does not match function's prototypenewmain.c:94: warning: (1464) number of arguments passed to function "__delay_us" does not match function's prototype:0: error: undefined symbols: __delay_ms(dist/default/production\STERGE.X.production.obj) __delay_us(dist/default/production\STERGE.X.production.obj) (908) exit status = 1make[2]: *** [dist/default/production/STERGE.X.production.hex] Error 1make[1]: *** [.build-conf] Error 2make: *** [.build-impl] Error 2make[2]: Leaving directory `C:/Users/Iliescu/MPLABXProjects/STERGE.X'make[1]: Leaving directory `C:/Users/Iliescu/MPLABXProjects/STERGE.X'BUILD FAILED (exit value 2, total time: 2s)Deci eroarea e UNDEFINED functions..

Link to comment
Share on other sites

Am inclus deja xc.h, stai sa vad daca merge, dar te referi la faptul ca pentru a pune delay de 40 de ms sa zicem, trebuie pus un for(int i=0;i<5;i++) __delay_ms(10); sau ma rog, sa il pui de 4 ori la rand? Adica nu merge schimbat argumentul? E absurd.

Link to comment
Share on other sites

Am facut acum un alt proiect, am copiat un cod care are deja rutinele astea, ca daca le scriu eu nu merge, tot imi da eroare, e ciudat :) ma cam enerveaza compilatorul asta nou de la microchip...Eu nu inteleg o chestie, deci pana la urma pinii de la display trebuie conectati pe porturile RB4- Rb7, nu?voidlcd_write(unsigned char c){__delay_us(40);LCD_DATA = ( ( c >> 4 ) & 0x0F ); // mi-a explicat aici cineva ca are ar face RB4-RB7 0, deci inteleg ca pinii astia 4 ii folosesc, nu?LCD_STROBE();LCD_DATA = ( c & 0x0F );LCD_STROBE();}Sau invers, pe 0 - 4?Multumesc tuturor pentru ajutor !!!

Link to comment
Share on other sites

LCD_DATA = ( ( c >> 4 ) & 0x0F ); /*Iti face bitii 3-0 ai portului egali cu bitii 7-4 al lui c dar bitii 7-4 ai portului ii face 0*/LCD_DATA = ( c & 0x0F ); /*Iti face bitii 3-0 ai portului egali cu bitii 3-0 al lui c dar bitii 7-4 ai portului ii face 0*/Deci bitii 7-4 ai portului ii face 0 si apare o problema daca tu mai ai ceva conectat acolo.

Link to comment
Share on other sites

unsigned char temp;temp = LCD_DATA;temp = temp & 0xF0temp = temp | ((c>>4)&0x0F);LCD_DATA = temp;

? Sa modific programul sa pun asta in loc sau ?Si inca o intrebare, eu am alimentare diferentiata pentru picsi pentru display, pentru display am pus un incarcator de telefon, pentru pic am lasat pickit2-ul pe vdd on. ideea e ca daca il programez cat timp am displayul conectat, imi da eroare, trebuie sa scot displayul din montaj, sa programez picul dupa care sa il pun iarasi. e corect sau nu?Si cu MCLR-ul eu in program in pragma config il pun OFF, si din pickit2 il tin in reset, e ok, nu?Stiu ca pot face MCLR-ul si " hardware ", adica sa il pun leg cu un switch si o rezistenta, dar credca merge si din program direct, nu?Ma gandesc ca circuitul pentru MCLR e util daca fac PCB-ul si nu o sa mai am pickitul conectat la el, dar asa, nu e nevoie, ma gandesc eu.
Link to comment
Share on other sites

Cum spune Elef. Se aplica la trimiterea datelor catre LCD.Sau asa. LCD_DATA = (LCD_DATA & 0xF0) | (c >> 4); /*Pentru high nibble*/LCD_DATA = (LCD_DATA & 0xF0) | c; /*Pentru low nibble*/Astea nu iti mai modifica bitii 7-4 ai portului.Sau daca vrei sa fii total safe:LCD_DATA = (LCD_DATA & 0xF0) | ((c >> 4) & 0x0F); /*Pentru high nibble*/LCD_DATA = (LCD_DATA & 0xF0) | (c & 0x0F); /*Pentru low nibble*/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share




×
×
  • 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