Ranbeer Singh
Full Member level 5
![Full Member level 5](/styles/images/ranks/flevel2.gif)
- Joined
- Jul 30, 2015
- Messages
- 259
- Helped
- 22
- Reputation
- 44
- Reaction score
- 22
- Trophy points
- 1,298
- Location
- Faridabad India
- Activity points
- 3,266
Hello All,
I am unable to send the 4 bit data to Pic18f2520 PORTC upper nibbles. Actually i do'not have any idea to send 4 bit data to 8 bit port. If i work with LCD library, It works fine...but i have manufactured my PCB's. So i am unable to change pins and gate it's benefit.
Pin description : -
My code are here
Please help
I am unable to send the 4 bit data to Pic18f2520 PORTC upper nibbles. Actually i do'not have any idea to send 4 bit data to 8 bit port. If i work with LCD library, It works fine...but i have manufactured my PCB's. So i am unable to change pins and gate it's benefit.
Pin description : -
EN = RC3
RS = RC2
R/W = GND
PORTC upper nibble = data out
RS = RC2
R/W = GND
PORTC upper nibble = data out
My code are here
Code:
#include <p18f2520.h>
#define RS_PIN PORTCbits.RC2 /* PORT for RS */
#define E_PIN PORTCbits.RC3 /* PORT for E */
//--------------------------------------------------------------------------
void LCD_Init(void);
void Str_LCD( const rom char *buffer);
void Chr_LCD(char data);
void Clear_LCD(void);
void Move_Corsor( char Line, char Pos);
//--------------------------------------------------------------------------
void Start_Display(void);
void Time_10ms(void);
void main()
{
TRISA=0xFF;
TRISC=0x00;
PORTC=0x00;
TRISB=0x01;
PORTB=0x00;
T0CON=0x06;
LCD_Init();
while(1)
{
Start_Display();
}
}
void Start_Display()
{
Str_LCD("SPEED- ");
Str_LCD("0000");
Str_LCD(" RPM");
Move_Corsor(2,0);
Str_LCD("Current- ");
Str_LCD("2.2");
Str_LCD(" A");
}
//---------------------------------------------------------------------------------------
void LCD_Init()
{
RS_PIN=0; //LCD instructions (RS) pin no. 4
Chr_LCD(0x28); //LCD clear
Chr_LCD(0x01); //LCD 4 bit, 2line, 5x7
Chr_LCD(0x0C); //LCD diplay-on cursor not blinking
Chr_LCD(0x80); //LCD cursor Pos. begain
RS_PIN=1; //LCD Data (RS)
}
void Str_LCD( const rom char *buffer)
{
while(*buffer) // Write data to LCD up to null
{
Chr_LCD(*buffer); // Write character to LCD
buffer++; // Increment buffer
}
return;
}
void Chr_LCD(char data)
{
TRISC &= 0x0F;
PORTC &= 0x0F;
PORTC |= data&0xF0;
Time_10ms();
Time_10ms();
Time_10ms();
E_PIN=1;
Time_10ms();
Time_10ms();
Time_10ms();
E_PIN=0;
PORTC &= 0x0F;
PORTC |= ((data<<4)&0xF0);
Time_10ms();
Time_10ms();
Time_10ms();
E_PIN=1;
Time_10ms();
Time_10ms();
Time_10ms();
E_PIN=0;
TRISC |= 0xF0;
}
void Clear_LCD(void)
{
RS_PIN=0;
Chr_LCD(0x01);
Chr_LCD(0x80);
RS_PIN=1;
}
void Move_Corsor( char Line, char Pos)
{
RS_PIN=0;
if(Line==1)Chr_LCD(0x80);
if(Line==2)Chr_LCD(0xC0);
while(Pos!=0)
{
Chr_LCD(0x14);
Pos--;
}
RS_PIN=1;
}
//---------------------------------------------------------------------------------------
void Time_10ms()
{
TMR0H=0xFE;
TMR0L=0x7A;
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMR0ON=0;
INTCONbits.TMR0IF=0;
}
Please help