blueroomelectronics
Well-Known Member
With careful programming 256 bytes of RAM can go a long way. Constants aren't RAM, neither are tables.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <p18cxxx.h>
#include <pwm.h>
#include <timers.h>
#include <delays.h>
#include <adc.h>
#include <usart.h>
#pragma config WDT = OFF, OSC = INTIO2, DEBUG =ON,MCLRE =ON,PWRT = OFF,BOR = OFF
int temp1;
int loop=1; // variable to count how many times program has looped
void main (void)
{
char DutyCyc = 0xffff;
TRISBbits.TRISB2 =0;
TRISAbits.TRISA0 =1;
OSCCON = 0x72; //8MHz clock
ADCON1=0x7e; //set RA0 to analogue
Nop();
OpenADC( ADC_FOSC_8 &
ADC_RIGHT_JUST &
ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS &
ADC_12_TAD,
ADC_CH0 &
ADC_INT_OFF, ADC_1ANA ); //This is a bit mask for the value ADCON1, this was setting AN0 as digital.
//Nop();
TRISBbits.TRISB0=0;
LATBbits.LATB2 =1;
TRISBbits.TRISB3=0;
// Open the USART configured as 8N1, 9600 baud
OpenUSART ( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,25);
LATBbits.LATB2=1;
SetOutputPWM1 (SINGLE_OUT, PWM_MODE_1);
OpenPWM1(DutyCyc);
while(1)
{
putcUSART(", temp1");
SetChanADC(ADC_CH0);
Delay10TCYx( 50 );
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for ADC conversion// Wait for ADC conversion
temp1 = ReadADC(); // Read result and put in temp
SetDCPWM1(DutyCyc);
loop=loop++;
if(loop==500) //800 for led
{
LATBbits.LATB0=0; //heart beat led
Nop();
}
if (loop==700) // 1000 for led
{
LATBbits.LATB0=1; //heartbeat led
loop=1;
}
}
}