MANJUNATHA K C
Newbie level 3
- Joined
- Mar 2, 2013
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,317
Dear Sir/Madam/Friends.
Below is my code to develop Real Time Clock Using PIC 16F886. Right now its working correctly, but the problem is while displaying in lcd it print the ascii value like 0 1 2 3 4 5 6 7 8 9 after 9 it prints : ;< = > ? @ A.....i j k etc...instead of printing 10 11 12 13.......59. What i do to print the decimal values in lcd from 0 to 59.
#include <pic.h>
#include "delay.h"
#include "delay.c"
#define LCD_RS RB5
#define LCD_EN RB4
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
__CONFIG (INTIO & MCLREN & PWRTEN & WDTDIS & CPD & CP & BOREN & LVPDIS & FCMDIS & IESODIS & DEBUGDIS);
__CONFIG ( BORV40);
void lcd_init(void);
void lcd_clear(void);
void lcd_Iout(char);
void init_ports(void);
void lcddata(unsigned int);
void main()
{
unsigned char sec=0,min=0,hour=0;
TRISB=0X00;
init_ports();
lcd_init();
for(;
{
sec=sec+1;
if(sec>59)
{
sec=0;
min=min+1;
if(min>59)
{
min=0;
hour=hour+1;
if(hour>24)
{
hour=0;
}
}
}
DelayMs(1000);
lcd_clear();
lcd_Iout(0x86);
lcddata(sec+48);
lcd_Iout(0x85);
lcddata(':');
lcd_Iout(0x83);
lcddata(min+48);
lcd_Iout(0x82);
lcddata(':');
lcd_Iout(0x80);
lcddata(hour+48);
}
}
void lcd_init(void)
{
LCD_RS = 0; // write control bytes
DelayMs(15); // power on delay
PORTB = 0x03; // attention!
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(20);
PORTB = 0x03; // attention!
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(100);
PORTB = 0x03; // attention!
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(100);
PORTB = 0x2; // set 4 bit mode
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(10);
lcd_Iout(0x28); // 4 bit mode, 1/16 duty, 5x8 font
lcd_Iout(0x0C); // display off
lcd_Iout(0x01);
lcd_Iout(0x06); // display on, blink curson on
return;
}
void init_ports(void)
{
PORTA = 0;
PORTB = 0;
PORTC = 0;
ANSEL = 0x01;
ANSELH = 0x00;
TRISA = 0b00000001;
TRISB = 0b00000000;
TRISC = 0b00011111;
return;
}
void lcddata(unsigned int ptr)
{
int i;
LCD_RS = 1; // write characters
PORTB = (PORTB & 0xF0) | (ptr >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) | (ptr & 0x0F);
LCD_STROBE;
DelayUs(100);
}
void lcd_Iout(unsigned char c)
{
LCD_RS = 0;
PORTB = (PORTB & 0xF0) | (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) | (c & 0x0F);
LCD_STROBE;
DelayUs(1000);
}
void lcd_clear(void)
{
LCD_RS = 0;
lcd_Iout(0x1);
DelayMs(4);
}
Below is my code to develop Real Time Clock Using PIC 16F886. Right now its working correctly, but the problem is while displaying in lcd it print the ascii value like 0 1 2 3 4 5 6 7 8 9 after 9 it prints : ;< = > ? @ A.....i j k etc...instead of printing 10 11 12 13.......59. What i do to print the decimal values in lcd from 0 to 59.
#include <pic.h>
#include "delay.h"
#include "delay.c"
#define LCD_RS RB5
#define LCD_EN RB4
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
__CONFIG (INTIO & MCLREN & PWRTEN & WDTDIS & CPD & CP & BOREN & LVPDIS & FCMDIS & IESODIS & DEBUGDIS);
__CONFIG ( BORV40);
void lcd_init(void);
void lcd_clear(void);
void lcd_Iout(char);
void init_ports(void);
void lcddata(unsigned int);
void main()
{
unsigned char sec=0,min=0,hour=0;
TRISB=0X00;
init_ports();
lcd_init();
for(;
{
sec=sec+1;
if(sec>59)
{
sec=0;
min=min+1;
if(min>59)
{
min=0;
hour=hour+1;
if(hour>24)
{
hour=0;
}
}
}
DelayMs(1000);
lcd_clear();
lcd_Iout(0x86);
lcddata(sec+48);
lcd_Iout(0x85);
lcddata(':');
lcd_Iout(0x83);
lcddata(min+48);
lcd_Iout(0x82);
lcddata(':');
lcd_Iout(0x80);
lcddata(hour+48);
}
}
void lcd_init(void)
{
LCD_RS = 0; // write control bytes
DelayMs(15); // power on delay
PORTB = 0x03; // attention!
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(20);
PORTB = 0x03; // attention!
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(100);
PORTB = 0x03; // attention!
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(100);
PORTB = 0x2; // set 4 bit mode
LCD_EN = 1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
LCD_EN = 0;
DelayMs(10);
lcd_Iout(0x28); // 4 bit mode, 1/16 duty, 5x8 font
lcd_Iout(0x0C); // display off
lcd_Iout(0x01);
lcd_Iout(0x06); // display on, blink curson on
return;
}
void init_ports(void)
{
PORTA = 0;
PORTB = 0;
PORTC = 0;
ANSEL = 0x01;
ANSELH = 0x00;
TRISA = 0b00000001;
TRISB = 0b00000000;
TRISC = 0b00011111;
return;
}
void lcddata(unsigned int ptr)
{
int i;
LCD_RS = 1; // write characters
PORTB = (PORTB & 0xF0) | (ptr >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) | (ptr & 0x0F);
LCD_STROBE;
DelayUs(100);
}
void lcd_Iout(unsigned char c)
{
LCD_RS = 0;
PORTB = (PORTB & 0xF0) | (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) | (c & 0x0F);
LCD_STROBE;
DelayUs(1000);
}
void lcd_clear(void)
{
LCD_RS = 0;
lcd_Iout(0x1);
DelayMs(4);
}