Estoy trabajando en un proyecto PIC para conectar un LCD de 4 bits. Mis líneas de datos para mi LCD está conectado a mi PORTC (PORTC0-3), pero necesito de 4 pines del puerto PORTC para conectarse a un 4 interruptores también (PORTC4-7). El PIC es un PIC16F886. El código de mi LCD.c está por debajo.
/*
* LCD Interface Example
* This code will interface to a standard LCD controller
* like the Hitachi HD44780. It uses it in 4 bit mode, with
* the hardware connected as follows (the standard 14 pin
* LCD connector is used):
*
* PORTC bits 0-3 are connected to LCD Data Bits 4-7 (High Nibble)
* PORTA bit 2 is connected to the LCD RS input (Register Select)
* RW input (Read/Write) is connected to Ground
* PORTA bit 1 is connected to the LCD EN bit (Enable)
*/
#include <htc.h>
#include "lcd.h"
void pause (unsigned short usvalue); //Establish pause routine function
#define LCD_RS RA2
#define LCD_RW RA4
#define LCD_EN RA1
#define LCD_DATA PORTC
#define LCD_STROBE() ((LCD_EN = 1), (LCD_EN = 0))
#define DelayS(T) {unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);} //Delay Macro
#define _XTAL_FREQ 4000000
/*Write a byte to the LCD in 4 bit mode*/
void
lcd_write(unsigned char c)
{
__delay_ms(1);
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 characters 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);
}
/*Initialize the LCD - put into 4 bit mode*/
void
lcd_init()
{
char init_value;
ANSEL = 0; //Disable Analog Pins on PORTA
init_value = 0x3;
TRISA = 0;
TRISC = 0;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;
__delay_ms(15); //Wait 15ms after Power applies)
LCD_DATA = init_value;
LCD_STROBE();
__delay_ms(10);
LCD_STROBE();
__delay_ms(10);
LCD_STROBE();
__delay_ms(10);
LCD_DATA = 2; //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
}
¿Hay alguna manera de "romper" hasta PORTC, así que puedo usar para la pantalla LCD y los interruptores.
Gracias por la ayuda proporcionada.