Hey nu ik kijk naar die code staat er
#define LDP PORTA //define MCU port connected to LCD data pins
#define LCP PORTA //define MCU port connected to LCD control pins
#define LDDR DDRA //define MCU direction register for port connected to LCD data pins
#define LCDR DDRA //define MCU direction register for port connected to LCD control pinsMaar in mijn programma stond er
DDRD = 0x00;
DDRB = 0xFF;
PORTB = 0xFF;Dus in de code denk ik te lezen portA connected met lcd, terwijl ik portB gebruikte? Heb nu mijn code veranderd in mijn programma maar dit veranderd niets?
Ik ga hier mijn drie files posten.
#include <avr/io.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <string.h>
#include "lcd_lib.h"
int main(void)
{
DDRD = 0x00;
DDRA = 0xFF;
PORTA = 0xFF;
LCDinit(); //init LCD
LCDsendCommand(0x01); //Clear LCD
LCDsendCommand(0x02); //Home position
LCDGotoXY(0x00, 0); //Position 0,0
LCDstring("TEST", 4); //Write TEST
while (1); // forever nothing
return 1;
}
//*****************************************************************************
//
// File Name : 'lcd_lib.c'
// Title : 8 and 4 bit LCd interface
// Author : Scienceprog.com - Copyright (C) 2007
// Created : 2007-03-29
// Revised : 2007-08-08
// Version : 1.0
// Target MCU : Atmel AVR series
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#include "lcd_lib.h"
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
void LCDdelayus(uint8_t cntr)
{
//50µs
uint8_t t=0;
while (t<cntr) {t++;asm volatile("nop" ::);}
}
void LCDdelayms(uint8_t cntr)
{
//5ms
uint8_t t=0;
while (t<cntr) {t++;LCDdelayus(33);}
}
void LCDset(uint8_t ch)
{
PORTA=ch;
//_delay_us(50);
//LCDdelayus(33);
PORTA=PORTA | 0x01; //set E-bit
//_delay_us(100);
//LCDdelayus(66);
PORTA=PORTA & 0xFE; //clear E-bit
//_delay_us(50);
//LCDdelayus(33);
}
void LCDsendChar(uint8_t ch) //Sends Char to LCD
{
uint8_t mem,t;
mem = ch;
ch = ch & 0xF0;
ch = ch | 0x02; //set RS
LCDset(ch);
ch = mem;
ch = (ch << 4) & 0xF0;
ch = ch | 0x02; //set RS
LCDset(ch);
//_delay_us(50);
LCDdelayus(33); //waarde 40 ==> 50µs; 1 while lus = 5 perioden; 1 periode = 0,25µs voor klok = 4MHz
}
void LCDsendCommand(uint8_t cmd) //Sends Command to LCD
{
uint8_t mem;
mem = cmd;
cmd = cmd & 0xF0;
LCDset(cmd);
cmd = mem;
cmd = (cmd << 4) & 0xF0;
LCDset(cmd);
//_delay_ms(5);
LCDdelayms(100); //waarde 100 ==> 100* 50µs; voor klok = 4MHz
}
void LCDinit(void)//Initializes LCD
{
//_delay_ms(1000);
DDRA=0xFF;
LCDset(0x38); //dummy value
//_delay_ms(5);
LCDdelayms(100);
LCDset(0x38); //dummy value
//_delay_ms(5);
LCDdelayms(100);
LCDset(0x38); //dummy value
//_delay_ms(5);
LCDdelayms(100);
LCDsendCommand(0x20); //4bit mode
LCDsendCommand(0x0C); //LCD ON
LCDsendCommand(0x03); //Entry mode
LCDsendCommand(0x01); //Clear LCD
LCDsendCommand(0x02); //Home position
}
void LCDstring(uint8_t* data, uint8_t nBytes) //Outputs string to LCD
{
register uint8_t i;
// check to make sure we have a good pointer
if (!data) return;
// print data
for(i=0; i<nBytes; i++)
{
LCDsendChar(data[i]);
}
}
void LCDGotoXY(uint8_t x, uint8_t y) //Cursor to X Y position
{
register uint8_t DDRAMAddr;
// remap lines into proper order
switch(y)
{
case 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; break;
case 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; break;
case 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; break;
case 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; break;
default: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;
}
// set data address
LCDsendCommand(1<<LCD_DDRAM | DDRAMAddr);
}
void LCDshiftLeft(uint8_t n) //Scrol n of characters Right
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x1E);
}
}
void LCDshiftRight(uint8_t n) //Scrol n of characters Left
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x18);
}
}
void LCDcursorOn(void) //displays LCD cursor
{
LCDsendCommand(0x0E);
}
void LCDcursorOnBlink(void) //displays LCD blinking cursor
{
LCDsendCommand(0x0F);
}
void LCDcursorOFF(void) //turns OFF cursor
{
LCDsendCommand(0x0C);
}
void LCDblank(void) //blanks LCD
{
LCDsendCommand(0x08);
}
void LCDvisible(void) //Shows LCD
{
LCDsendCommand(0x0C);
}
void LCDcursorLeft(uint8_t n) //Moves cursor by n poisitions left
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x10);
}
}
void LCDcursorRight(uint8_t n) //Moves cursor by n poisitions left
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x14);
}
}
//adapted fro mAVRLIB
void LCDprogressBar(uint8_t progress, uint8_t maxprogress, uint8_t length)
{
uint8_t i;
uint16_t pixelprogress;
uint8_t c;
// draw a progress bar displaying (progress / maxprogress)
// starting from the current cursor position
// with a total length of "length" characters
// ***note, LCD chars 0-5 must be programmed as the bar characters
// char 0 = empty ... char 5 = full
// total pixel length of bargraph equals length*PROGRESSPIXELS_PER_CHAR;
// pixel length of bar itself is
pixelprogress = ((progress*(length*PROGRESSPIXELS_PER_CHAR))/maxprogress);
// print exactly "length" characters
for(i=0; i<length; i++)
{
// check if this is a full block, or partial or empty
// (u16) cast is needed to avoid sign comparison warning
if( ((i*(uint16_t)PROGRESSPIXELS_PER_CHAR)+5) > pixelprogress )
{
// this is a partial or empty block
if( ((i*(uint16_t)PROGRESSPIXELS_PER_CHAR)) > pixelprogress )
{
// this is an empty block
// use space character?
c = 0;
}
else
{
// this is a partial block
c = pixelprogress % PROGRESSPIXELS_PER_CHAR;
}
}
else
{
// this is a full block
c = 5;
}
// write character to display
LCDsendChar(c);
}
}
//*****************************************************************************
//
// File Name : 'lcd_lib.h'
// Title : 8 and 4 bit LCd interface
// Author : Scienceprog.com - Copyright (C) 2007
// Created : 2007-03-29
// Revised : 2007-08-08
// Version : 1.0
// Target MCU : Atmel AVR series
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef LCD_LIB
#define LCD_LIB
#include <inttypes.h>
//Uncomment this if LCD 4 bit interface is used
//******************************************
#define LCD_4bit
//***********************************************
#define LCD_RS 1 //define MCU pin connected to LCD RS
//#define LCD_RW 1 //define MCU pin connected to LCD R/W
#define LCD_E 0 //define MCU pin connected to LCD E
#define LCD_D0 2 //define MCU pin connected to LCD D0
#define LCD_D1 2 //define MCU pin connected to LCD D1
#define LCD_D2 2 //define MCU pin connected to LCD D1
#define LCD_D3 3 //define MCU pin connected to LCD D2
#define LCD_D4 4 //define MCU pin connected to LCD D3
#define LCD_D5 5 //define MCU pin connected to LCD D4
#define LCD_D6 6 //define MCU pin connected to LCD D5
#define LCD_D7 7 //define MCU pin connected to LCD D6
#define LDP PORTA //define MCU port connected to LCD data pins
#define LCP PORTA //define MCU port connected to LCD control pins
#define LDDR DDRA //define MCU direction register for port connected to LCD data pins
#define LCDR DDRA //define MCU direction register for port connected to LCD control pins
#define LCD_CLR 0 //DB0: clear display
#define LCD_HOME 1 //DB1: return to home position
#define LCD_ENTRY_MODE 2 //DB2: set entry mode
#define LCD_ENTRY_INC 1 //DB1: increment
#define LCD_ENTRY_SHIFT 0 //DB2: shift
#define LCD_ON_CTRL 3 //DB3: turn lcd/cursor on
#define LCD_ON_DISPLAY 2 //DB2: turn display on
#define LCD_ON_CURSOR 1 //DB1: turn cursor on
#define LCD_ON_BLINK 0 //DB0: blinking cursor
#define LCD_MOVE 4 //DB4: move cursor/display
#define LCD_MOVE_DISP 3 //DB3: move display (0-> move cursor)
#define LCD_MOVE_RIGHT 2 //DB2: move right (0-> left)
#define LCD_FUNCTION 5 //DB5: function set
#define LCD_FUNCTION_8BIT 0 //DB4: set 8BIT mode (0->4BIT mode)
#define LCD_FUNCTION_2LINES 3 //DB3: two lines (0->one line)
#define LCD_FUNCTION_10DOTS 2 //DB2: 5x10 font (0->5x7 font)
#define LCD_CGRAM 6 //DB6: set CG RAM address
#define LCD_DDRAM 7 //DB7: set DD RAM address
// reading:
#define LCD_BUSY 7 //DB7: LCD is busy
#define LCD_LINES 2 //visible lines
#define LCD_LINE_LENGTH 16 //line length (in characters)
// cursor position to DDRAM mapping
#define LCD_LINE0_DDRAMADDR 0x00
#define LCD_LINE1_DDRAMADDR 0x40
#define LCD_LINE2_DDRAMADDR 0x14
#define LCD_LINE3_DDRAMADDR 0x54
// progress bar defines
#define PROGRESSPIXELS_PER_CHAR 6
void LCDdelayus(uint8_t cntr);
void LCDdelayms(uint8_t cntr);
void LCDset(uint8_t); //JVQ to set data on PORTA
void LCDsendChar(uint8_t); //forms data ready to send to 74HC164
void LCDsendCommand(uint8_t); //forms data ready to send to 74HC164
void LCDinit(void); //Initializes LCD
void LCDclr(void); //Clears LCD
void LCDhome(void); //LCD cursor home
void LCDstring(uint8_t*, uint8_t); //Outputs string to LCD
void LCDGotoXY(uint8_t, uint8_t); //Cursor to X Y position
void CopyStringtoLCD(const uint8_t*, uint8_t, uint8_t);//copies flash string to LCD at x,y
void LCDdefinechar(const uint8_t *,uint8_t);//write char to LCD CGRAM
void LCDshiftRight(uint8_t); //shift by n characters Right
void LCDshiftLeft(uint8_t); //shift by n characters Left
void LCDcursorOn(void); //Underline cursor ON
void LCDcursorOnBlink(void); //Underline blinking cursor ON
void LCDcursorOFF(void); //Cursor OFF
void LCDblank(void); //LCD blank but not cleared
void LCDvisible(void); //LCD visible
void LCDcursorLeft(uint8_t); //Shift cursor left by n
void LCDcursorRight(uint8_t); //shif cursor right by n
// displays a horizontal progress bar at the current cursor location
// <progress> is the value the bargraph should indicate
// <maxprogress> is the value at the end of the bargraph
// <length> is the number of LCD characters that the bargraph should cover
//adapted from AVRLIB - displays progress only for 8 bit variables
void LCDprogressBar(uint8_t progress, uint8_t maxprogress, uint8_t length);
#endif
Je LCD code gaat er van uit dat je hem aangesloten hebt op port A.
Ik zou eigenlijk zeggen, gebruik even picbasic en maak daar eenzelfde simpel test programma. In picbasic heb je dat zo geschreven, en je kunt daar zeker van zijn dat de code werkt.
Dat weet je hiervan niet zeker.
Ik wil je best helpen met het picbasic programma.
Moet je wel even een lijstje geven met hoe je PIC aangesloten is.
Heb geen PIC 
Maar mijn lcd werkt dus duidelijk op alleen maar op spanning, want als ik mijn connector versteek, of als ik er gewoon mijn µC uit haal, blijft die zwarte lijn er op staan, voor de rest wil er maar niets gebeuren.
Heb alle connectoren nog eens getest, en alles zit goed verbonden...
Zou het kunnen dat ik hem anders moet aansluiten? dat het geen HD44780 compatible is?
oeps, even ergens van uit gegaan wat niet klopt, sorry!
Het feit dat je een zwarte lijn ziet betekend gewoon dat je LCD werkt.
aansturing zal verkeerd zijn en daardoor blijft alleen de zwarte lijn staan.
(ik ga er van uit dat je wel je contrast in kunt stellen, en de zwart lijn daarmee wel weg kunt krijgen maar dan zie je niets)
aan de foto's te zien zeg ik toch dat het HD44780 is, maar het zou natuurlijk altijd iets anders kunnen zijn.
Kun je geen andere library's vinden die makkelijker te gebruiken zijn?
[Bericht gewijzigd door hvwieren op (32%)]
Heb je een 10k pot tussen contrast (pin 3) en gnd? (sluit de 5v NIET op de pot aan!)?
Zorg er voor dat de lijn net zichtbaar is, dus NIET pikzwart. Grote kans dat je het contrast zo heb ingesteld dat ie zo - wie - zo zwart is.
hadv
Just find out what you like and let it kill you
Op 14 juli 2007 13:36:56 schreef ElecM:
ik heb een progger, de vm111
Is hetzelfde als de K8048, voor PIC's dus.
Hadv, topic is halverwege 'gekaapt'
huidige probleem eigenaar schreef dit in zijn eerste bericht:
Op 14 april 2010 16:36:57 schreef immortaljin:
Hey, ik heb ook een display met die gegevens daarop, maar bij mij is hij 24x2.Ik heb hem aangesloten aan mijn microcontroller, (aan mijn stk500), maar ik krijg alleen de zwarte blokjes (continu)
PS: heb hem aangesloten op volgende manier:
http://www.avr-asm-tutorial.net/avr_en/LCD4_500.html
EDIT: ik zie dat in 'lcd_lib.c' alle delay routines weggecommentarieerd zijn en vervangen door eigen routines.
Waarom? en kloppen de tijden nog?
Langer wachtten is nooit erg, korter wachtten wel.
[Bericht gewijzigd door hvwieren op (16%)]
@hvwieren geen probleem xD moet ik misschien eens aanschaffen ^^
waar moet ik andere libraries precies halen? 
@Iemand Ja heb er een pot tussen van 10K, al paar keer aan gedraaid, maar hij werkt enkel maar tegen het einde, dus als de weerstand praktisch niets is, is een kleine draai voldoende om zijn contrast direct te wijzigen.
@hvwieren de lcd_lib.c heb ik gekregen van mijn leerkracht, wat zou er moeten aan veranderd worden om dit te doen werken?