#include <p18f452.h>
#include <stdio.h>
#include <stdlib.h>
#include "LCD.h"
#include "delays.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 in1 PORTAbits.RA0
#define in2 PORTAbits.RA1
#define in3 PORTAbits.RA2
#define d1 PORTAbits.RA3
#define d2 PORTAbits.RA5
#define d3 PORTEbits.RE0
#define d4 PORTEbits.RE1
#define d5 PORTEbits.RE2
#define d6 PORTCbits.RC3
unsigned char i1[17];
//////////////////
void cls(void)
{
writecommand(0x01);
Delay1KTCYx(10);
writecommand(0x02);
Delay10TCYx(10);
}
unsigned int meter(unsigned int me,unsigned char states)
{
unsigned int i;
i=0;
if(states==1)
{
INTCONbits.TMR0IF=0;
T0CON=0xA8;
i=TMR0H;
i=i<<8;
i=i | TMR0L;
return i;
}
INTCONbits.TMR0IF=0;
TMR0H=0;
TMR0L=0;
T0CON=0xA8;
while(i<=me)
{
i=TMR0H;
i=i<<8;
i=i | TMR0L;
}
T0CON=0x00;
return i;
}
unsigned int zav(unsigned int me,unsigned char states)
{
unsigned int i;
i=0;
if(states==1)
{
i=TMR1H;
i=i<<8;
i=i | TMR1L;
return i;
}
PIR1bits.TMR1IF=0;
TMR1H=0;
TMR1L=0;
T1CON=0x83;
while(i<=me)
{
i=TMR1H;
i=i<<8;
i=i | TMR1L;
}
T1CON=0x00;
return i;
}
///////////////////
void main(void)
{
unsigned int i;
ADCON1=6;
/////timers
TRISAbits.RA0=1;
TRISAbits.RA1=1;
TRISAbits.RA2=1;
TRISAbits.RA3=1;
TRISAbits.RA4=1;
TRISCbits.RC0=1;
///// Outputs
TRISB=0;
TRISAbits.RA3=0;
TRISAbits.RA5=0;
TRISEbits.RE0=0;
TRISEbits.RE1=0;
TRISEbits.RE2=0;
TRISCbits.RC3=0;
TXSTA=0x20;
SPBRG=5;
TXSTAbits.TXEN=1;
RCSTAbits.SPEN=1;
d1=0;
d2=0;
d3=0;
d4=0;
d5=0;
d6=0;
lcdinit();
i=0;
sprintf(i1,"%d",strlen(" IDLE"));
lcdprint(i1);
//////////////////////////
while(1)
{
cls();
if(in3==1){
d2=0;
d1=1;
sprintf(i1,"Hello Man");
}
else
{
d1=0;
d2=1;
sprintf(i1,"Hello Iran");}
lcdprint(i1);
TXREG='S';
while(PIR1bits.TXIF==0);
Delay10KTCYx(100);
}
}