Hi all,
I have been reading articles from this form for a while now and have learned much. This is my first post with a problem I have not been able to figure out. I was given an assignment to write to an LCD screen with some basic information followed by a capital letter made of special characters. This assignment has been completed and is working correctly. The problem was found when I was playing with the circuit. I found if I used PORTAbits.7 or PORTAbits.6 the circuit would not display characters. Can anyone tell me why this is so?
Thank you for any commits
I have been reading articles from this form for a while now and have learned much. This is my first post with a problem I have not been able to figure out. I was given an assignment to write to an LCD screen with some basic information followed by a capital letter made of special characters. This assignment has been completed and is working correctly. The problem was found when I was playing with the circuit. I found if I used PORTAbits.7 or PORTAbits.6 the circuit would not display characters. Can anyone tell me why this is so?
Thank you for any commits
Rich (BB code):
#include<p18f1320.h>
#include <stdio.h>
#pragma config WDT = OFF
#pragma config PWRT = ON
#pragma config LVP = OFF
#pragma config MCLRE = OFF
#pragma config OSC = INTIO2
#define RS PORTAbits.RA3
#define RW PORTAbits.RA4
#define E PORTAbits.RA7
void lcd_setup(void);
void write(char message);
void delay(int time);
void bflag (void);
void movlcd(int x);
void lcdcmd(int x);
void creatchar(void);
void usechar(int x);
void black_out(int x);
void makechar (int a, int b, int c,int d,int e,int f,int g,int h);
void main(void)
{
OSCCON = 0x70;
ADCON1 = 0x7F;
TRISA = 0;
TRISB = 0;
creatchar();
lcd_setup();
bflag();
lcdcmd(0x80);
bflag ();
write('R');
bflag ();
write('y');
bflag ();
write('a');
bflag ();
write('n');
bflag ();
lcdcmd(0xC0);
bflag ();
write('R');
bflag ();
write('e');
bflag ();
write('e');
bflag ();
write('d');
bflag ();
lcdcmd(0x90);
bflag ();
write('I');
bflag ();
write('n');
bflag ();
write('d');
bflag ();
write('u');
bflag ();
write('s');
bflag ();
write('t');
bflag ();
write('r');
bflag ();
write('i');
bflag ();
write('a');
bflag ();
write('l');
bflag ();
lcdcmd(0xD0);
bflag ();
write('C');
bflag ();
write('o');
bflag ();
write('n');
bflag ();
write('t');
bflag ();
write('r');
bflag ();
write('o');
bflag ();
write('l');
bflag ();
write('s');
bflag ();
write(' ');
bflag ();
write('4');
bflag ();
write('3');
bflag ();
write('0');
bflag ();
write('4');
bflag ();
delay(6000);
lcdcmd(0x01); //clears LCD
bflag ();
black_out(85);
black_out(21);
black_out(69);
black_out(6);
black_out(71);
lcdcmd(0x96); //0
write(0x00);
lcdcmd(0x97); //1
bflag ();
write(0x01);
lcdcmd(0xD8); //2
bflag ();
write(0x02);
lcdcmd(0xD7); //3
bflag ();
write(0x03);
lcdcmd(0xC6); //4
bflag ();
write(0x04);
lcdcmd(0x85); //5
bflag ();
write(0x05);
lcdcmd(0x87); //6
bflag ();
write(0x06);
lcdcmd(0xC7); //7
bflag ();
write(0x07);
while(1);
}
void black_out(int x)
{
x = 128 + x;
lcdcmd(x);
bflag ();
write(0xFF);
bflag();
}
void lcdcmd(int x)
{
RS = 0;
RW = 0;
PORTB = x;
E=1;
delay(1);
E=0;
}
void write(char message)
{
RS=1;
RW=0;
PORTB = message;
E=1;
delay(1);
E=0;
}
void delay( int time)
{
unsigned int i,j;
for (i=0; i<time; i++)
for(j=0;j<165; j++)
;
}
void bflag (void)
{
TRISB = 0xFF;
RW = 1;
RS = 0;
do
{
E=1;
delay(1);
E=0;
}
while(PORTBbits.RB7 == 1);
TRISB = 0;
}
void lcd_setup(void)
{
RS = 0;
RW = 0;
PORTB = 0x30;
E = 1;
delay(1);
E = 0;
RS = 0;
RW = 0;
PORTB = 0x30;
E = 1;
delay(1);
E = 0;
RS = 0;
RW = 0;
PORTB = 0x30;
E = 1;
delay(1);
E = 0;
RS = 0;
RW = 0;
PORTB = 0x38;
E = 1;
delay(1);
E = 0;
RS = 0;
RW = 0;
PORTB = 0x08;
E = 1;
delay(1);
E = 0;
RS = 0;
RW = 0;
PORTB = 0x0C;
E = 1;
delay(1);
E = 0;
RS = 0;
RW = 0;
PORTB = 0x06;
E = 1;
delay(1);
E = 0;
RS = 0;
RW = 0;
PORTB = 0x01;
E = 1;
delay(1);
E = 0;
}
void creatchar(void)
{
RS=0;
RW=0;
PORTB = 0x40;
delay(1);
E=1;
delay(1);
E=0;
delay(1);
RS = 1;
RW = 0;
makechar(31,31,31,7,3,1,0,0); //0
delay(1);
makechar(28,24,24,24,28,30,31,31); //1
delay(1);
makechar(16,24,28,30,31,31,15,7); //2
delay(1);
makechar(7,3,1,0,0,0,0,0); //3
delay(1);
makechar(27,17,0,0,0,0,17,27); //4
delay(1);
makechar(7,15,31,31,31,31,31,31); //5
delay(1);
makechar(28,30,31,31,31,31,31,31); //6
delay(1);
makechar(31,31,31,31,31,31,30,28); //7
delay(1);
}
void makechar (int a, int b, int c,int d,int e,int f,int g,int h)
{
PORTB = a;
E=1;
delay(1);
E=0;
delay(1);
PORTB = b;
E=1;
delay(1);
E=0;
delay(1);
PORTB = c;
E=1;
delay(1);
E=0;
delay(1);
PORTB = d;
E=1;
delay(1);
E=0;
delay(1);
PORTB = e;
E=1;
delay(1);
E=0;
delay(1);
PORTB = f;
E=1;
delay(1);
E=0;
delay(1);
PORTB = g;
E=1;
delay(1);
E=0;
delay(1);
PORTB = h;
E=1;
delay(1);
E=0;
delay(1);
}
Last edited by a moderator: