I am trying my to implement a simple program such that my PIC24F displays a string of characters on my LCD screen. Unfortunately, nothing is being written on screen and on debugging it seems that PORTA and PORTB pins never change from their initial 0 state. Cannot understand why this is happening :S
Am using the Microstick to program my PIC24FV16KM202 together with the following code:
Please help :S
Am using the Microstick to program my PIC24FV16KM202 together with the following code:
Code:
/* Delay Function being used throughout the program */
void delay(int num)
{
int i =0;
for (i=0; i<num; i++)
{
;
}
}
/* LCD_command function to send a command to LCD */
void LCD_command(unsigned char c)
{
LCD_rs = 0; /* Disable register select */
LCD_rw = 0; /* Disable Read/Write */
LCD_en = 1; /* Enable */
delay(200);
LCD_data = c; /* Write Command on LCD pin */
delay(200);
LCD_en = 0; /* Disable */
}
/* Function to Initialize LCD */
void Init_LCD(void)
{
LCD_rs = 0;
LCD_rw = 0;
delay(800);
LCD_en = 1;
delay(500);
LCD_en = 0;
delay(500);
LCD_en = 1;
delay(500);
LCD_en = 0;
LCD_command(0x38); /*Function Set: 2 Line, 8-bits, 5x7 dots*/
LCD_command(0x08); /*Display Off*/
LCD_command(0x0F); /*Display On, Cursor On*/
LCD_command(0x06); /*Entry Mode*/
LCD_command(0x80); /*Entry Mode DDRAM address*/
}
/* Function to clear the LCD Screen */
void Clear_LCD(void)
{
LCD_rs = 0;
LCD_command(0x1); /* Clear Command */
delay(800);
}
/* Function to write a character onto LCD */
void Write_char_LCD(unsigned char c)
{
LCD_rw = 0;
LCD_rs = 1;
LCD_en = 1;
delay(200);
LCD_data = c; /* c is the character to be written */
delay(200);
LCD_en = 0;
}
/* Function to write a string of characters on LCD */
void Write_string_LCD(const char *s)
{
LCD_rs = 1;
while(*s)
{
Write_char_LCD(*s++); /* Write each character in string, one at a time */
}
}
int main(void)
{
unsigned int i;
// Set up output pin for LED
TRISB = 0x0000;
TRISAbits.TRISA0 = 0;
TRISAbits.TRISA1 = 0;
TRISAbits.TRISA2 = 0;
TRISAbits.TRISA3 = 0;
PORTAbits.RA1 = 0;
PORTAbits.RA2 = 0;
PORTAbits.RA3 = 0;
OSCCONbits.COSC = 0x7;
OSCCONbits.NOSC = 0x7;
CLKDIVbits.RCDIV = 0x6;
Init_LCD();
Clear_LCD();
while(1)
{
Write_string_LCD("***pH Meter***");
delay(100);
// To make the LED blink visibly, we have to wait a while between toggling
// the LED pin.
for(i = 0; i < 65535; i++)
{
Nop();
Nop();
Nop();
Nop();
}
// Toggle the LED output pin to alternate between the LED being on and off
LATAbits.LATA0 ^= 1;
}
}
Please help :S