Hi,
I'm trying to build a little circuit which displays some info from a GPS-module.
The module is EM - 411
The display is a 2x20 LCD.
I know the display is working. (I've tested with another code)
I know the GPS is working. (I've tested it against another PCs serialport via MAX232 IC)
I've googled and read datasheets for days, but now I'm stuck, and I think I've found where it goes down the drain...
This is the main.c - file:
This is the lcd_mod.h - file:
This is the usart.c - file
I want the PIC to receive data from the EM-411 in PIN 7 (RB1), and display whatever on the LCD. I know that input = getchar only puts one character in input, but that is ok for now. Then I know that it's working.
I think the error is in the lcd-mod.c - file. The line:
Defines all of PORTB to LCD_DATA and the PIC's RX-pin is RB1, so I think that this overrules the Rx function.
Am I right or way off?
If I'm right, how should I configure LCD_DATA to be only RB4:RB7? Which is the datapins for the LCD.
MPLAB 8.63
Hi tech C V9.8
I'm trying to build a little circuit which displays some info from a GPS-module.
The module is EM - 411
The display is a 2x20 LCD.
I know the display is working. (I've tested with another code)
I know the GPS is working. (I've tested it against another PCs serialport via MAX232 IC)
I've googled and read datasheets for days, but now I'm stuck, and I think I've found where it goes down the drain...
This is the main.c - file:
Rich (BB code):
/*
Circuit
LCD module:
PIN 1: GND -> GND
PIN 2: +5v -> +5v
PIN 3: 5Kpot
PIN 4: RS -> RA2
PIN 5: RW -> RA3
PIN 6: EN -> RB3
PIN 11: D4 -> RB4
PIN 12: D5 -> RB5
PIN 13: D6 -> RB6
PIN 14: D7 -> RB7
GSP module:
PIN 1: GND
PIN 2: Vin
PIN 3: TX -> RB1
PIN 4: RX -> RB2
PIN 5: GND
PIN 6: Not Connected
*/
// Definitions and includes
#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 4000000
#endif
#include <htc.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
#include "usart.h"
#include "usart.c"
#include "lcd-mod.c"
// Configuration
__CONFIG (WDTEN & PWRTEN & MCLRDIS & BOREN & LVPDIS & UNPROTECT & INTIO);
// Prototype functions
// Gloabal variables
char input;
char buffer[19];
// Functions
// Main
void main()
{
INTCON = 0;
CMCON =0x07;
init_comms();
lcd_init();
lcd_goto(0);
while (1)
{
input = getchar();
itoa(buffer, input, 10);
lcd_puts(buffer);
__delay_us(250);
} // end while
} // end main
Rich (BB code):
/*
* lcd-mod.c
*/
#include "lcd.h"
#define LCD_RS RA2
#define LCD_RW RA3
#define LCD_EN RB3
#define LCD_DATA PORTB
#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 & 0xF0 );//skriv mest signifikant nibble (4 bit)
LCD_STROBE();
LCD_DATA = ((c >> 4) | (c << 4)& 0xF0);//Skriv minst signifikant nibble
//LCD_DATA = ( ( c >> 4 ) & 0x0F );
LCD_STROBE();
}
/*
* Clear and home the LCD
*/
void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x10);
__delay_ms(20);
}
/* 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;
// ADCON1 = 0x06; // Disable analog pins on PORTA
init_value = 0x30;//endret fra 0x3 til 0x30
TRISA=0;
TRISB= 0b00000100;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;
__delay_ms(15); // 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 = 0x20;//endret fra 2 til 0x20
// 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
}
Rich (BB code):
#ifndef _SERIAL_H_
#define _SERIAL_H_
#define BAUD 9600
#define FOSC 4000000L
#define NINE 0 /* Use 9bit communication? FALSE=8bit */
#define DIVIDER ((int)(FOSC/(16UL * BAUD) -1))
#define HIGH_SPEED 1
#if NINE == 1
#define NINE_BITS 0x40
#else
#define NINE_BITS 0
#endif
#if HIGH_SPEED == 1
#define SPEED 0x4
#else
#define SPEED 0
#endif
#ifndef _16F628
#define RX_PIN TRISB1
#define TX_PIN TRISB2
#endif
/* Serial initialization */
#define init_comms()\
RX_PIN = 1; \
TX_PIN = 1; \
SPBRG = DIVIDER; \
RCSTA = (NINE_BITS|0x90); \
TXSTA = (SPEED|NINE_BITS|0x20)
void putch(unsigned char);
unsigned char getch(void);
unsigned char getche(void);
#endif
I think the error is in the lcd-mod.c - file. The line:
Rich (BB code):
#define LCD_DATA PORTB
Am I right or way off?
If I'm right, how should I configure LCD_DATA to be only RB4:RB7? Which is the datapins for the LCD.
MPLAB 8.63
Hi tech C V9.8