baby_1
Advanced Member level 1
Hello
here is my program
problem:
1-when i powered up the MCU it start from 3 or 7(in first increasing but the next increasing it works fine)?why it doen't work properly in the first step?
according ascii table when i add 48 to each number it returns the ascii number ( for example if i=0 the ascii should be 48) but it doesn't show me the 0 it start from 1 !!!!
why?
here is my program
Code:
#include <p18f452.h>
#include <delays.h>
#include <stdio.h>
#pragma config OSC=HSPLL
#pragma config DEBUG=OFF
#pragma config WDT=OFF
#pragma config BOR=OFF
#pragma config LVP=OFF
#pragma config PWRT=ON
#define LED PORTDbits.RD3
#define rs PORTDbits.RD0
#define en PORTDbits.RD1
#define datas PORTB
void writedata(unsigned char s){
rs=1;
en=0;
datas=s;
en=1;
Delay10TCYx(10);
en=0;
Delay10TCYx(10);
}
void writecommand(unsigned char s){
rs=0;
en=0;
datas=s;
en=1;
Delay10TCYx(10);
en=0;
Delay10TCYx(10);
}
void lcdinit()
{
Delay1KTCYx(1);
writecommand(0x38);
Delay1KTCYx(1);
writecommand(0x0E);
Delay1KTCYx(1);
}
void numtostring(unsigned char *s)
{
}
unsigned char i;
void main(void)
{
TRISDbits.RD3=0;
TRISB=0;
TRISDbits.RD0=0;
TRISDbits.RD1=0;
LED=1;
lcdinit();
writecommand(0x01);
while(1)
{
if (i>10)
{
i=0;
writecommand(0x01);
writecommand(0x02);
}
Delay10TCYx(10);
writedata(i+48);
Delay10KTCYx(50);
LED=~LED;
i=i+1;
}
}
problem:
1-when i powered up the MCU it start from 3 or 7(in first increasing but the next increasing it works fine)?why it doen't work properly in the first step?
according ascii table when i add 48 to each number it returns the ascii number ( for example if i=0 the ascii should be 48) but it doesn't show me the 0 it start from 1 !!!!
why?