Re: Using PIC18F4520 TO control a DC 12V FAN.ANYONE hav the
hi tahmid, i got a problem.this is my program.
i cannot display the "standby"
this project is to display standby when there is power ,if i turn the power down to 0v the display "FC power on" come out and i can turn the potentiometer to display voltage and current.can u help e to see what wrong with my code
#include <p18f4520.h>
#include <delays.h>
#include <stdlib.h>
int result,x,a,c,w,e;
double y,z,f,g;
void Init_LCD(void);
void PTM(void);
void W_ctr_4bit(char);
void W_data_4bit(char);
#define LCD_DATA PORTD
#define LCD_RW PORTAbits.RC4
#define LCD_RS PORTAbits.RC5
#define LCD_E PORTAbits.RC3
unsigned char LCD_TEMP, i;
char MESS[8]="standby";
char MESS2[10]="FC PWR ON";
char VOLT[3]="V=";
char VOLT2[2]="V";
char DOT[2]=".";
char CURR[3]="C=";
char CURR2[3]="uA";
//char POWR[3]="P=";
//char TEMP[5]="TEM=";
//char TEMP2[2]="C";
char BLANK[5]=" ";
void InterruptHandlerLow(void);
float mps,temp;
#pragma code InterruptVectorLow= 0x018
void InterruptVectorLow(void)
{
_asm
goto InterruptHandlerLow
_endasm
}
#pragma code
#pragma interruptlow InterruptHandlerLow
void InterruptHandlerLow()
{
if (INTCONbits.TMR0IF) // Activate Timer0
{
TMR0H = 0xF8; // Set Timer0's Interval ON for 4m Sec
TMR0L = 0x2F;
w++;
PTM();
INTCONbits.TMR0IF = 0;
}
if(PIR1bits.TMR1IF)
{
if(g>0)//
{
W_ctr_4bit(0x80);
for(i=0; i<9; i++)
{
W_data_4bit(MESS);
}
else if(g=<0)//
{
W_ctr_4bit(0x80);
for(i=0; i<11; i++)
{
W_data_4bit(MESS2);
}
delay10TCYx(1);//
Enable=1;
}
else
{
Enable=0;
}
if(Enable=1)
{
W_ctr_4bit(0x80);
for(i=0; i<4; i++)
{
W_data_4bit(VOLT);
}
W_ctr_4bit(0x82);
itoa(x,BLANK);
i=0;
while(BLANK)
{
W_data_4bit(BLANK);
i++;
}
W_ctr_4bit(0x83);
for(i=0; i<3; i++)
{
W_data_4bit(DOT);
}
W_ctr_4bit(0x84);
itoa(a,BLANK);
i=0;
while(BLANK)
{
W_data_4bit(BLANK);
i++;
}
W_ctr_4bit(0x86);
for(i=0; i<3; i++)
{
W_data_4bit(VOLT2);
}
c=y*1000;
W_ctr_4bit(0x88);
for(i=0; i<4; i++)
{
W_data_4bit(CURR);
}
W_ctr_4bit(0x8A);
itoa(c,BLANK);
i=0;
while(BLANK)
{
W_data_4bit(BLANK);
i++;
}
W_ctr_4bit(0x8E);
for(i=0; i<4; i++)
{
W_data_4bit(CURR2);
}
/*W_ctr_4bit(0xc0);
for(i=0; i<4; i++)
{
W_data_4bit(POWR);
}*/
}
else
{
Enable=0;
}
TMR1H=0x0b;
TMR1L=0xdc;
PIR1bits.TMR1IF=0;
}
}
void main()
{
TRISA=0b11101111;
TRISB=0b11110000;
TRISC=0b10000010;
TRISD=0;
ADCON0bits.ADON = 1; // Enable ADC
ADCON1 = 0x0D; // Enable AN0~AN1 while others are Digital I/O
ADCON2 = 0x84; // Right justified, manual acquistion, Fosc/4
INTCONbits.GIE=0;
Init_LCD();
/*for(i=0;i<15;i++)
{
W_data_4bit(MESS);
}*/
PORTB=0b00000110;
RCONbits.IPEN=1;
TMR0H = 0xF8; // Set Timer0's Interval OFF for 4m Sec
TMR0L = 0x2F;
IPR1bits.TMR1IP=0;
TMR1H=0x0b;
TMR1L=0xdc;
T0CON = 0x80; // Set Timer0's Setup & 16-bit mode, Internal Clk=4/4MHz, Prescaler=2
T1CON=0b11110001;
PIR1bits.TMR1IF=0;
PIE1bits.TMR1IE=1;
INTCON = 0xE4; // Enable Global Interrupt w Enable TMR0's Interrupt W Set TMR0's Flag
while(1);
}
void PTM()
{
if(w == 0)
{
ADCON0bits.CHS0 = 0;
ADCON0bits.CHS1 = 0;
ADCON0bits.CHS2 = 0;
ADCON0bits.CHS3 = 0;
}
else if(w == 1)
{
ADCON0bits.CHS0 = 1;
ADCON0bits.CHS1 = 0;
ADCON0bits.CHS2 = 1;
ADCON0bits.CHS3 = 0;
}
else
w = -1;
ADCON0bits.GO = 1;
while(!ADCON0bits.GO);
if(w == 0) //main supply
{
main = ADRESH * 256 + ADRESL;
e=(5*temp)/1024;
f=(5*temp)/1024;
g=f-e;
}
else if(w == 1) //FC supply
{
temp = ADRESH * 256 + ADRESL;
x=(5*temp)/1024;
y=(5*temp)/1024;
z=y-x;
a=z*100;
}
}
void Init_LCD()
{
Delay1KTCYx(15);
W_ctr_4bit(0x03);
Delay1KTCYx(5);
W_ctr_4bit(0x02);
W_ctr_4bit(0b00101000);
W_ctr_4bit(0b00001100);
W_ctr_4bit(0b00000110);
W_ctr_4bit(0b00000001);
}
void W_ctr_4bit(char x)
{
LCD_RW=0;
LCD_RS=0;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
LCD_TEMP=x;
LCD_TEMP &=0x0f;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
}
void W_data_4bit(char x)
{
LCD_RW=0;
LCD_RS=1;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
LCD_TEMP=x;
LCD_TEMP &=0x0f;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
}