Temp Sensor on 8051F320

Thread Starter

gusmas

Joined Sep 27, 2008
239
Hey

Ok so am using keil microvision 4, and I am using the onboard temp sensor in the micro controller, now I configured the ADC inside the micro to use a interrupt when a conversion is complete, the only problem I have is to simulate my code, since the it seems in my case the interrupt cant be generated in my code, i have to go trigger the interrupt myself in peripherals on keil v4. My code is below, just need a verdict if my code is going to work or not.

Rich (BB code):
#include <c8051F320.h>

void init_clock(void);
void init_UART(void);
void init_tempSensor(void);
void init_ADC(void);
void ADC_Interupt(void);
sbit en_ADC = ADC0CN^7;
unsigned int temp;
void main (void)
{
    init_clock();
    init_UART();
    init_tempSensor();
    init_ADC();
    EA = 1;
    en_ADC = 1;    //enable ADC0
    while(1);
}

void init_clock(void)
{
     CLKSEL = 0;             //Selects internal clock
     OSCICL = 0;             //clear the internal clock calibration
     OSCICN = 0x83;         //System Clock is devided by 1. SYSCLOCK  = 12MHZ
}


//Baudrate is 9615
void init_UART(void)
{
     CKCON = 0x01;             //Configure prescaled bits to devide the system clock by 4.
    SCON0 = 0x50;            //RI0 will only be activated if stop bit is logic level 1.
      TMOD = 0x20;            //Timer 1 configured in 8-Bit auto reload
      TH1 = 100;                //TH1 reload value
     TR1 = 1;                //Timer 1 start
     TI0 = 1;                //Transmit Interupt of UART is enabled
}

void init_tempSensor(void)
{
     REF0CN = 0x07;           //Enable temp sensor, analogue bias generator, internal voltage reference is used.
}

void init_ADC(void)
{
    ADC0CF = 0x1C;          //Configure SAR Conversion clock and left justify configuration for ADC0
    ADC0CN = 0x10;         //ADC0 in Lower Power Mode,Normal Track Mode,ADCBUSY bit is set.
    AMX0P = 0x1E;         //ADC0 Positive Input is In Chip Temp Sensor
    AMX0N = 0x1F;          //ADC0 Negative Input is ground, also know as being configured in Single Ended Mode
    EIE1 = 0x08;           //Enable ADC interrupt when a conversion is complete
        
}

void ADC_Interupt(void) interrupt 10
{
     AD0INT = 0;
     temp =  ADC0L + (ADC0H <<8);
}
 
Last edited by a moderator:
Top