di seguito ci sono i miei codici:
- Codice: Seleziona tutto
#define _LEGACY_HEADERS
#include <htc.h>
__CONFIG (HS & WDTDIS & PWRTEN & BORDIS & LVPDIS & DUNPROT & WRTEN & UNPROTECT);
#include "delay.c"
#include "lcd_busy.c"
void main (void)
{
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;
TRISD=0b00000000;
LCD_INIT();
DelayMs(250);
LCD_CLEAR();
DelayUs(200);
while(1)
{
LCD_GOTO(1,1);
LCD_PUTS("CIAO A TUTTI");
LCD_GOTO(2,1);
LCD_PUTS("RIGA 2");
}
}
file lcd
- Codice: Seleziona tutto
/************************************************************************
Use this includes if these files are not included in your main code
************************************************************************/
//#include "PIC.h"
//#include "delay.c"
/************************************************************************
Use the following defines to set the lines as your hardware requires
You can use ANY output line of the MCU, even on several ports :)
************************************************************************/
#define LCD_RW RD1 // Read / Write register (19/10/2011 by Gabriel)
#define LCD_RS RD2 // Register select
#define LCD_EN RD3 // Enable
#define LCD_D4 RD4 // LCD data 4
#define LCD_D4_TRIS TRISD4 // LCD data 4 tris (19/10/2011 by Gabriel)
#define LCD_D5 RD5 // LCD data 5
#define LCD_D5_TRIS TRISD5 // LCD data 5 tris (19/10/2011 by Gabriel)
#define LCD_D6 RD6 // LCD data 6
#define LCD_D6_TRIS TRISD6 // LCD data 6 tris (19/10/2011 by Gabriel)
#define LCD_D7 RD7 // LCD data 7
#define LCD_D7_TRIS TRISD7 // LCD data 7 tris (19/10/2011 by Gabriel)
/************************************************************************
Now you have only to write LCD Rows and Columns number
and the cursor behaviour
/************************************************************************
!!! NOTE !!!
Some 1x16 LCD works as 2x8!!! ...be sure how to configure
yours, see its datasheet!!!
************************************************************************/
#define LCD_ROWS 2 // valid numbers are: 1,2 (set to 2 for 2 or more rows)
#define LCD_COLS 20 // valid numbers are: 8,16,20
#define LCD_CURSOR_VISIBLE 0 // 1:cursor on 0:cursor off
#define LCD_CURSOR_BLINK 0 // 1:cursor blinks 0:cursor doesn't blinks
#define LCD_TYPEWRITE 0 // 1:delay between characters
#define LCD_TW_DELAY 50 // milliseconds between characters
/************************************************************************
YOUR LCD IS NOW READY TO WORK!!! :)
YOU CAN IGNORE THE FOLLOWING CODE
ENJOY !!!
************************************************************************/
// define the right control value to set the cursor behavior
#if LCD_CURSOR_VISIBLE==1
#if LCD_CURSOR_BLINK==1
#define LCD_CONTROL 0b00001111
#else
#define LCD_CONTROL 0b00001110
#endif
#else
#define LCD_CONTROL 0b00001100
#endif
/************************************************************************
Use the following defines to send fast command to the LCD
Ex.: LCD_CMD(LCD_line2); will set the cursor on line 2
You can add fast command of your own!!!
*************************************************************************
!!! NOTE !!!
DON'T CHANGE THE DEFINES WITHIN #if-#endif
*************************************************************************/
#define LCD_CLR 0x01 // Clears Display
#define LCD_HOME 0x02 // Cursor to Home position
#define LCD_line1 0x80 // Cursor to Line 1 position 1
#define LCD_line2 0xC0 // Cursor to Line 2 position 1
#if (LCD_COLS==20)
#define LCD_line3 0x94 // Cursror to Line 3 position 1 (20 char LCD)
#define LCD_line4 0xD4 // Cursor to Line 4 position 1 (20 char LCD)
#else
#define LCD_line3 0x90 // Cursor to Line 3 position 1 (16 char LCD)
#define LCD_line4 0xD0 // Cursor to Line 4 position 1 (16 char LCD)
#endif
/************************************************************************/
/****************************************
Enable LCD to read data
*****************************************/
void LCD_STROBE (void)
{
LCD_EN = 1;
DelayUs(1);
LCD_EN=0;
DelayUs(1);
}
/****************************************
LCD BUSY
(19/10/2011 by Gabriel)
*****************************************/
bit LCD_BUSY (void)
{
static bit busyFlag;
static bit tempRS;
LCD_D4_TRIS = 1; // Set data lines D7-D4 as input
LCD_D5_TRIS = 1;
LCD_D6_TRIS = 1;
LCD_D7_TRIS = 1;
tempRS = LCD_RS; // Save the LCD_RS value
LCD_RW = 1; // Set Read mode
LCD_RS = 0; // Command mode
LCD_EN = 1; // read bits 4-7 (bit7 = busy status)
DelayUs(1);
busyFlag = LCD_D7; // copy busy status in busyFlag var
LCD_EN = 0;
DelayUs(1);
LCD_STROBE(); // read bit 0-3 (not used)
LCD_D4_TRIS = 0; // Set data lines D7-D4 as output
LCD_D5_TRIS = 0;
LCD_D6_TRIS = 0;
LCD_D7_TRIS = 0;
LCD_RW = 0; // Set write mode
LCD_RS = tempRS; // Load LCD_RS with the value saved
return busyFlag;
}
/****************************************
Write a nibble to the LCD
****************************************/
void LCD_NIBBLE_OUT (unsigned char c)
{
if (c & 0b10000000)
LCD_D7=1;
else LCD_D7=0;
if (c & 0b01000000)
LCD_D6=1;
else LCD_D6=0;
if (c & 0b00100000)
LCD_D5=1;
else LCD_D5=0;
if (c & 0b00010000)
LCD_D4=1;
else LCD_D4=0;
LCD_STROBE();
}
/****************************************
Write a byte to the LCD (4 bit mode)
****************************************/
void LCD_WRITE (unsigned char c)
{
while(LCD_BUSY());
LCD_RW = 0; // write mode
LCD_NIBBLE_OUT(c);
c <<= 4;
LCD_NIBBLE_OUT(c);
DelayUs(50);
#if LCD_TYPEWRITE==1
if (LCD_RS)
{
DelayMs(LCD_TW_DELAY); // Delay between characters
}
#endif
}
/****************************************
Sends a command to the LCD
****************************************/
void LCD_CMD (char c)
{
LCD_RS = 0; // writes command
LCD_WRITE(c);
}
/****************************************
GoTo specified line and position
****************************************/
void LCD_GOTO (char line,char pos)
{
switch(line)
{
case 1: LCD_CMD((LCD_line1-1)+pos);
break;
case 2: LCD_CMD((LCD_line2-1)+pos);
break;
case 3: LCD_CMD((LCD_line3-1)+pos);
break;
case 4: LCD_CMD((LCD_line4-1)+pos);
}
}
/****************************************
Clears and Home LCD
*****************************************/
void LCD_CLEAR (void)
{
LCD_CMD(LCD_CLR);
DelayMs(3);
}
/****************************************
Writes one character (ASCII) to LCD
****************************************/
void LCD_PUTCH (char c)
{
LCD_RS = 1; // write characters
LCD_WRITE(c);
}
/****************************************
Writes unsigned numbers to the LCD
*****************************************/
void LCD_PUTUN (unsigned int c)
{
unsigned char t1,i,wrote;
unsigned int k;
wrote = 0;
for (i=4;i>=1;i--)
{
switch(i)
{
case 4: k=10000;
break;
case 3: k=1000;
break;
case 2: k=100;
break;
case 1: k=10;
}
t1=c/k;
if((wrote)||(t1!=0))
{
LCD_PUTCH(t1+'0');
wrote=1;
}
c-=(t1*k);
}
LCD_PUTCH(c+'0');
}
/****************************************
Writes signed numbers to the LCD
*****************************************/
void LCD_PUTSN (signed int c)
{
if(c<0)
{
LCD_PUTCH('-');
c*=(-1);
}
LCD_PUTUN(c);
}
/****************************************
Writes a string to the LCD
****************************************/
void LCD_PUTS (const char * s)
{
LCD_RS = 1; // write characters
while(*s)
LCD_WRITE(*s++);
}
/****************************************
Customizes the CGRAM characters (0-7)
****************************************/
void LCD_CUSTOMCHAR(unsigned char pos,unsigned char byte0,unsigned char byte1,unsigned char byte2,unsigned char byte3,unsigned char byte4,unsigned char byte5,unsigned char byte6,unsigned char byte7)
{
LCD_CMD(0b00001000); // display off
LCD_CLEAR();
LCD_CMD(64+(pos*8)); // goto the right CGRAM location
LCD_PUTCH(byte0);
LCD_PUTCH(byte1);
LCD_PUTCH(byte2);
LCD_PUTCH(byte3);
LCD_PUTCH(byte4);
LCD_PUTCH(byte5);
LCD_PUTCH(byte6);
LCD_PUTCH(byte7);
LCD_CMD(LCD_CONTROL); // display on with preferred settings
}
/****************************************
Initializes LCD
****************************************/
void LCD_INIT (void)
{
LCD_RS = 0; // write control bytes
LCD_EN = 0;
LCD_RW = 0;
DelayMs(50); // power on delay orig 50
LCD_D4=1;
LCD_D5=1;
LCD_D6=0;
LCD_D7=0;
LCD_STROBE();
DelayMs(6);
LCD_STROBE();
DelayUs(150);
LCD_STROBE();
DelayMs(6);
LCD_D4=0; // set 4 bit mode
LCD_STROBE();
DelayUs(100);
#if (LCD_ROWS==1)
LCD_WRITE(0b00100000); // 4 bit mode, 1 line, 5x8 font
#else
LCD_WRITE(0b00101000); // 4 bit mode, 2 or more lines, 5x8 font
#endif
LCD_WRITE(0b00001000); // display off
LCD_WRITE(0b00000000); // clear display
LCD_WRITE(LCD_CONTROL); // display on, set the cursor behavior as specified
LCD_WRITE(0b00000110); // entry mode, display not shifted, cursor increments
}
/************************************************************************/
#undef LCD_ROWS
#undef LCD_COLS
#undef LCD_CURSOR_BLINK
#undef LCD_CURSOR_VISIBLE
/************************************************************************
!!! END !!!
THANKS FOR EXAMINING MY CODE ;)
/************************************************************************
Please report any bug or suggestion at zypkin@inwind.it
************************************************************************/
inoltre ci sono i file di delay ma quelli non danno problemi.
gli errori che riporta il compilatore sono i seguenti:
- Codice: Seleziona tutto
CLEAN SUCCESSFUL (total time: 583ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/imac/Desktop/ADC_PIC16F874A/adc_pic16f874a.X'
make -f nbproject/Makefile-default.mk dist/default/production/adc_pic16f874a.X.production.hex
make[2]: Entering directory `C:/Users/imac/Desktop/ADC_PIC16F874A/adc_pic16f874a.X'
"C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 ../delay.c -q --chip=16F874A -P --outdir="build/default/production\_ext\1472" -D_LEGACY_HEADERS -N31 --warn=0 --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --double=24 --float=24 --addrqual=ignore --mode=pro -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s"
"C:\Program Files\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 ../lcd_busy.c -q --chip=16F874A -P --outdir="build/default/production\_ext\1472" -D_LEGACY_HEADERS -N31 --warn=0 --runtime=default,+clear,+init,-keep,+osccal,-resetbits,-download,-stackcall,+clib --summary=default,-psect,-class,+mem,-hex --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --double=24 --float=24 --addrqual=ignore --mode=pro -g --asmlist "--errformat=%%f:%%l: error: %%s" "--msgformat=%%f:%%l: advisory: %%s" "--warnformat=%%f:%%l warning: %%s"
../lcd_busy.c:177: error: undefined identifier "RD3"
../lcd_busy.c:178 warning: function declared implicit int
../lcd_busy.c:191: error: undefined identifier "TRISD4"
../lcd_busy.c:192: error: undefined identifier "TRISD5"
../lcd_busy.c:193: error: undefined identifier "TRISD6"
../lcd_busy.c:194: error: undefined identifier "TRISD7"
../lcd_busy.c:196: error: undefined identifier "RD2"
../lcd_busy.c:197: error: undefined identifier "RD1"
../lcd_busy.c:200: error: undefined identifier "RD3"
../lcd_busy.c:202: error: undefined identifier "RD7"
../lcd_busy.c:224: error: undefined identifier "RD7"
../lcd_busy.c:228: error: undefined identifier "RD6"
../lcd_busy.c:232: error: undefined identifier "RD5"
../lcd_busy.c:236: error: undefined identifier "RD4"
../lcd_busy.c:249: error: undefined identifier "RD1"
../lcd_busy.c:267: error: undefined identifier "RD2"
../lcd_busy.c:297 warning: function declared implicit int
../lcd_busy.c:305: error: undefined identifier "RD2"
../lcd_busy.c:366: error: undefined identifier "RD2"
../lcd_busy.c:396: error: undefined identifier "RD2"
../lcd_busy.c:397: error: undefined identifier "RD3"
../lcd_busy.c:398: error: undefined identifier "RD1"
../lcd_busy.c:402: error: undefined identifier "RD4"
../lcd_busy.c:402: advisory: too many errors (21)
make[2]: Leaving directory `C:/Users/imac/Desktop/ADC_PIC16F874A/adc_pic16f874a.X'
make[1]: Leaving directory `C:/Users/imac/Desktop/ADC_PIC16F874A/adc_pic16f874a.X'
make[2]: *** [build/default/production/_ext/1472/lcd_busy.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)



