// JuneBug Info
// Buttons RB0, RB2, RB5.
// Analog AN1, AN3
// IR RB0
// LED's RA0, RA6, RA7
//
// configuration
#pragma*config OSC = INTIO2, WDT = OFF, LVP = OFF, PWRT = ON, BOR = OFF
#include <stdlib.h>
#include <p18f1320.h>
#include <usart.h>
#include <adc.h>
#include <delays.h>
#include <portb.h>
unsigned char config;
unsigned int spbrg;
int reslta0;
int reslta3;
int reslts0;
int reslts3;
char A1;
char B1;
void main(void)
{
OpenUSART (USART_ASYNCH_MODE &
USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
25 );
OpenADC (ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD,
ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 03);
while (1)
{
SetChanADC(ADC_CH1);
Delay10TCYx(5);
ConvertADC();
while( BusyADC() );
reslta0 = ReadADC();
reslts0 = (reslta0+1)*500/1024;
itoa (reslts0, A1);
SetChanADC(ADC_CH3);
Delay10TCYx(5);
ConvertADC();
while( BusyADC() );
reslta3 = ReadADC();
}
}
...
char A1;
...
itoa (reslts0, A1);
...
...
char A1[5];
...
itoa (reslts0, A1);
...
Try setting the internal clock speed.
Code:void main(void) { // select 8MHz OSCCONbits.IRCF0=1; OSCCONbits.IRCF1=1; OSCCONbits.IRCF2=1; ....
debugging using pickit2/junebug is "slow" you cannot expect "real time speed", that's the downside of ICD. ICE is much faster (and many times more expensive)...
Have you set a breakpoint or you are doing "step by step". Set breakpoint at the end of the while loop and check the values there, should be much faster.
That aside, you have error in your code:
Code:... char A1; ... itoa (reslts0, A1); ...
itoa second parametar is char array not char, so when you execute this itoa, the address that is contained in A1 variable will be filled with "garbage" making any sort of troubles ...
if you do want to use itoa, change the code to:
Code:... char A1[5]; ... itoa (reslts0, A1); ...
I saw that. I wanted to get back to using "C", not that basic is bad or anything. I am grabbing snippets here and there to get back into it. I want to write as 'functions' / 'modules' and get them working one by one to get used to working with "C" then put them together for a program.I'm actually learning C30 currently but I posted a Swordfish BASIC 10bit 4 channel A/D to UART program in JPUG #2.
Try setting the internal clock speed.
Code:void main(void) { // select 8MHz OSCCONbits.IRCF0=1; OSCCONbits.IRCF1=1; OSCCONbits.IRCF2=1; ....
Get the datasheet for the 18F1320.Where can I find a list of these bit settings, been going thru the couple of pdf's that I d/l from Microchip but did not find this info.
Tnx, Mike.
Exactly what "tidbits" are you looking for?Yup, Got that. It's great for .asm, I also have C18_User Guide & C18_Libraries, but the tidbits posted aren't in there, haven't stopped searchin though..
Exactly what "tidbits" are you looking for?
Could it be that you're looking for the C18 header file for 18F1320? You'll find it in "directory_where_you_installed_it\MCC18\h". Most likely C:\MCC18\h
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?