Ahoj,
ze stránek Microchipu jsem si stáhnul program na odzkoušení LCD microchip.com/forums/m530430-print.aspx ale po zapojení mi to na LCD vypíše požadované znaky, ale hned se to přepíše čtverečkama.
Hlavní progran je zde:
#include <htc.h>
#include "lcd.h"
#include <stdio.h>
#define _XTAL_FREQ 4000000
void main(void)
{
ANSEL = 0; // Disable adc
CM1CON0 = 0; //Turn off Comparator 1
CM2CON0 = 0; //Turn off Comparator 2
TRISB = 0; // PORTB all outputs
TRISC = 0;
lcd_init(); // PORTC all outputs
lcd_goto(0); // select first line
lcd_puts("1234567891263512");
lcd_goto(0x40); // Select second line
lcd_puts("Hello ");
}
A knihovna k LCD tu:
#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 4000000
#endif
#include <htc.h>
#include "lcd.h"
#define LCD_RS RB6
#define LCD_RW RB5
#define LCD_EN RB4
#define LCD_DATA PORTC
#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
/* write a byte to the LCD in 4 bit mode */
void
lcd_write(unsigned char c)
{
__delay_us(40);
LCD_DATA = ( ( c >> 4 ) & 0x0F );
LCD_STROBE();
LCD_DATA = ( c & 0x0F );
LCD_STROBE();
}
/*
* Clear and home the LCD
*/
void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}
/* write a string of chars to the LCD */
void
lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}
/* write one character to the LCD */
void
lcd_putch(char c)
{
LCD_RS = 1; // write characters
lcd_write( c );
}
/*
* Go to the specified position
*/
void
lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}
/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
char init_value;
init_value = 0x3;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;
__delay_ms(50); // wait 15mSec after power applied,
LCD_DATA = init_value;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
LCD_DATA = 2; // Four bit mode
LCD_STROBE();
lcd_write(0x28); // Set interface length
lcd_write(0x0F); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x06); // Set entry Mode
}
administrator: přejmenováno z “16F690 a LCD 16x2 v C - nejede”