Have this setup,
16F690 2*16LCD., connected data 4-7 on RB4-7
RC0 RS, RC1 enable
Do i need x-tal on PIC to get the party going ?,
Is there not an internal x-tal,
Or is it another problem,
Here is Main and LCD.c
And lcd.c
This lcd. code works fine in another project with other MCU,
Other project i have done with 16F690 has allways been with external x-tal.
What to do ?
I only get first line of LCD filled with squares.
16F690 2*16LCD., connected data 4-7 on RB4-7
RC0 RS, RC1 enable
Do i need x-tal on PIC to get the party going ?,
Is there not an internal x-tal,
Or is it another problem,
Here is Main and LCD.c
Code:
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
#include <string.h>
// CONFIG
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Selection bits (BOR enabled)
#pragma config IESO = ON // Internal External Switchover bit (Internal External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
static void interrupt isr(void) // Here is interrupt function - the name is unimportant.
{
}
void setup(void)
{
IRCF0=1; // 8 mhz
IRCF1=1;
IRCF2=1;
SCS=0; // internel clock
TRISA0=1; //set all A port in
TRISA0=1;
TRISA1=1;
TRISA2=1;
TRISA3=1;
TRISA4=1;
TRISA5=1;
TRISB4=0; // = out
TRISB5=0;
TRISB6=0;
TRISB7=0;
TRISC0=0; // Out
TRISC1=0;
TRISC2=1; // Other in;
TRISC3=1;
TRISC4=1;
TRISC5=1;
TRISC6=1;
TRISC7=1;
ANSEL=0; // all digital.
}
void main(void) {
setup();
lcd_init();
lcd_goto(0);
lcd_puts("Hello");
while (1)
{
}
}
Code:
#ifndef _XTAL_FREQ
// Unless specified elsewhere, 8MHz system frequency is assumed
#define _XTAL_FREQ 8000000
#endif
#include <htc.h>
#include "lcd.h"
#define LCD_RS RC0
#define LCD_EN RC1
#define LCD_D4 RB4 // Data bits
#define LCD_D5 RB5 // Data bits
#define LCD_D6 RB6 // Data bits
#define LCD_D7 RB7 // Data bits
#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)
{ static unsigned char temp;
temp=c;
__delay_us(320);
if(c & 0x80) LCD_D7=1; else LCD_D7=0;
if(c & 0x40) LCD_D6=1; else LCD_D6=0;
if(c & 0x20) LCD_D5=1; else LCD_D5=0;
if(c & 0x10) LCD_D4=1; else LCD_D4=0;
LCD_STROBE();
if(c & 0x08) LCD_D7=1; else LCD_D7=0;
if(c & 0x04) LCD_D6=1; else LCD_D6=0;
if(c & 0x02) LCD_D5=1; else LCD_D5=0;
if(c & 0x01) LCD_D4=1; else LCD_D4=0;
LCD_STROBE();
}
/*
* Clear and home the LCD
*/
void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(16);
}
/* 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()
{
//NY RUTINE
LCD_RS = 0; // write control bytes
__delay_ms(280);// power on delay
LCD_D4 = 1; // init!
LCD_D5 = 1; //
LCD_STROBE();
__delay_ms(40);
LCD_STROBE(); // init!
__delay_us(800);
LCD_STROBE(); // init!
__delay_us(40);
LCD_D4 = 0; // set 4 bit mode
LCD_STROBE();
__delay_us(320);
lcd_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
lcd_write(0x0C);// display on
lcd_write(0x06);// entry mode advance cursor
lcd_write(0x01);// clear display and reset cursor
}
Other project i have done with 16F690 has allways been with external x-tal.
What to do ?
I only get first line of LCD filled with squares.