kylemaes
Banned
heres my code
The part that doesnt work is:
And the INIT is:
Now anyways the problem, I have only RA0 RA1 and RA2 available to use... And the it doesnt have ANY input signal! I have had all my stuff working just fine on a PIC16F877A but im trying to update to a 18F pic with USB so I can controll stuff... What is wrong with this code? (I have tried with C18's librarys aswell same problem) Thankyou so much for helping me
Code:
#include <p18f2550.h>
#include "delays.h"
#include "adc.h"
#pragma config PLLDIV = 1, CPUDIV = OSC1_PLL2, USBDIV = 1, FOSC = HS, FCMEN = OFF, IESO = OFF
#pragma config PWRT = ON, BOR = OFF, VREGEN = OFF, WDT = OFF, PBADEN = OFF, LPT1OSC = OFF, MCLRE = OFF
#pragma config STVREN = OFF, LVP = OFF, DEBUG = OFF
void main(void); /* main code */
void foo(void); /* Interupt Service Routine */
void lcd_init();
void Write_LCD();
void Busy_flag();
void Strobe_LCD();
void OpenADC(unsigned char config,
unsigned char config2 ,
unsigned char portconfig);
int ReadADC( void );
void SetChanADC( unsigned char channel );
/*****************************************************************************************************************************/
#define E PORTAbits.RA5
#define RS PORTAbits.RA4
#define RW PORTAbits.RA3
char fare = 0;
char huns = 0;
char tens = 0;
char ones = 0;
char huns2 = 0;
char tens2 = 0;
char ones2 = 0;
char remain = 0;
char mainnum = 0;
const char ScreenData[39] = {
0x41, //A 0
0x42, //B 1
0x43, //C 2
0x44, //D 3
0x45, //E 4
0x46, //F 5
0x47, //G 6
0x48, //H 7
0x49, //I 8
0x4A, //J 9
0x4B, //K 10
0x4C, //L 11 //CHARACTER DEFINITIONS!
0x4D, //M 12
0x4E, //N 13
0x4F, //O 14
0x50, //P 15
0x51, //Q 16
0x52, //R 17
0x53, //S 18
0x54, //T 19
0x55, //U 20
0x56, //V 21
0x57, //W 22
0x58, //X 23
0x59, //Y 24
0x5A, //Z 25
0x20, //SPACE 26
0x3A, //: 27
0x30, //0 28
0x31, //1 29
0x32, //2 30
0x33, //3 31
0x34, //4 32
0x35, //5 33
0x36, //6 34
0x37, //7 35
0x38, //8 36
0x39, //9 37
0x25 //% 38
};
void Busy_Flag()
{
RW = 1; //read mode
while(PORTBbits.RB7); //Loop until finished
RW=0; //default to write mode...
}
void Strobe_LCD()
{
E=1;
Delay1KTCYx(4);
E=0;
}
void Write_LCD(unsigned char d,unsigned char x) //USE "Write_LCD(tabledata,1=cap0=lowercase);" (IF number Cap selection must equal 0!)
{
char z = 0x00;
if(!x)
{
z=0x20;
}
TRISB=0x00;
PORTB=d+z;
Strobe_LCD();
Busy_Flag();
TRISB=0xFF;
}
void lcd_init()
{
Write_LCD(0x38,1);
Write_LCD(0x0C,1);
Write_LCD(0x01,1);
}
void AddressDisplay(unsigned char c)
{
Busy_Flag(); //check LCD ready
TRISB = 0x00; //PORTB output
RW = 0; //write mode
RS=0; //command mode
PORTB=c; //place data on data port
TRISB = 0; //PORTB output
Strobe_LCD();
RS=1;
TRISB = 0xFF; //PORTB input
}
const char programnametext[16] = {
2,14,12,15,14,18,19,4,17,26,26,21,4,17,27,30
/*Co m p o s t e r V e r : 2*/
};
programname()
{
char a = 0;
char b;
char c;
Write_LCD(0x01,1);
RS = 1;
while(a != 16)
{
if((a==14) | (a==0) | (a==9) | (a==10) | (a==15) | (a==11)){c=1;}
Write_LCD(ScreenData[programnametext[a]],c);
c=0;
a++;
}
RS = 0;
}
/*****************************************************************************************************************************/
void main()
{
TRISA=0x07;
TRISB=0xFF;
TRISC=0;
lcd_init();
programname();
/**************************/
RCONbits.IPEN = 1; /* Set Priorities */
INTCONbits.GIEL = 0; /* disable low priority interrupts */
INTCONbits.GIEH = 1; /* enable high priority interrupts */
T1CONbits.RD16 = 1; /* Enable 16bit read/write of timer. */
T1CONbits.T1CKPS1 = 0;
T1CONbits.T1CKPS0 = 1; //INTERRUPT SETUP TIMER0
T1CONbits.TMR1CS = 0; /* Increment every instructrion cycle */
IPR1bits.TMR1IP = 1; /* Make high priority interrupt */
T1CONbits.TMR1ON = 1; /* Enable the timer */
PIE1bits.TMR1IE = 1; /* Enable timer1 interrupt */
TRISAbits.RA1=1;
TRISAbits.RA2=1;
/**/
ADCON1 = 0b00001011; //-Vref=Vdd, +Vref=Vss, AN0:An3 inputs,
ADCON0 = 0b00000000;
ADCON2 = 0b10101010; // (Fosc/32), 12 TAD (LM35 needs longer time, higher impedance)
ADCON0bits.ADON = 1; //Turn On ADC
/**/
/*************************/
while(1)
{
}
}
#pragma interrupt foo
void foo(void)
{
if(mainnum == 1)
{
ADCON0bits.GO_DONE = 1;//Start A/D Conversion
while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
fare=ADRESH; //TEMPERATURE
fare=fare*100;
fare=fare/255;
huns2=fare/100;
remain=fare-(huns2*100);
tens2=remain/10;
ones2=remain-(tens2*10);
}
//*******************+DISPLAY*************************//
if(mainnum == 2)
{
RS=1;
AddressDisplay(0xC0); //FANSPEED
Write_LCD(ScreenData[5],1);
Write_LCD(ScreenData[0],0);
Write_LCD(ScreenData[13],0);
Write_LCD(ScreenData[27],1);
if(!huns){Write_LCD(ScreenData[26],1);}else{Write_LCD(ScreenData[28+huns],1);}
Write_LCD(ScreenData[28+tens],1);
Write_LCD(ScreenData[28+ones],1);
Write_LCD(ScreenData[38],1);
AddressDisplay(0x90);
Write_LCD(ScreenData[19],1);
Write_LCD(ScreenData[4],0);
Write_LCD(ScreenData[12],0);
Write_LCD(ScreenData[15],0);
Write_LCD(ScreenData[27],1);
if(!huns2){Write_LCD(ScreenData[26],1);}else{Write_LCD(ScreenData[28+huns2],1);} //FOR TEMPERATURE!
Write_LCD(ScreenData[28+tens2],1);
Write_LCD(ScreenData[28+ones2],1);
Write_LCD(ScreenData[26],1);
Write_LCD(ScreenData[3],0);
Write_LCD(ScreenData[4],0);
Write_LCD(ScreenData[6],0);
RS=0;
}
if(mainnum == 3)
{
mainnum = 0;
}
mainnum++;
INTCONbits.TMR0IF=0;
}
#pragma code highvector=0x08
void highvector(void)
{
_asm goto foo _endasm
}
#pragma code
The part that doesnt work is:
Code:
ADCON0bits.GO_DONE = 1;//Start A/D Conversion
while(ADCON0bits.GO_DONE==1);//Loop here until A/D conversion completes;
fare=ADRESH; //TEMPERATURE
fare=fare*100;
fare=fare/255;
huns2=fare/100;
remain=fare-(huns2*100);
tens2=remain/10;
ones2=remain-(tens2*10);
And the INIT is:
Code:
ADCON1 = 0b00001011; //-Vref=Vdd, +Vref=Vss, AN0:An3 inputs,
ADCON0 = 0b00000000;
ADCON2 = 0b10101010; // (Fosc/32), 12 TAD (LM35 needs longer time, higher impedance)
ADCON0bits.ADON = 1; //Turn On ADC
Now anyways the problem, I have only RA0 RA1 and RA2 available to use... And the it doesnt have ANY input signal! I have had all my stuff working just fine on a PIC16F877A but im trying to update to a 18F pic with USB so I can controll stuff... What is wrong with this code? (I have tried with C18's librarys aswell same problem) Thankyou so much for helping me
Last edited: