Temp Sensor on 8051F320

Discussion in 'Embedded Systems and Microcontrollers' started by gusmas, Mar 4, 2011.

  1. gusmas

    Thread Starter Active Member

    Sep 27, 2008
    239
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2. #include <c8051F320.h>
    3.  
    4. void init_clock(void);
    5. void init_UART(void);
    6. void init_tempSensor(void);
    7. void init_ADC(void);
    8. void ADC_Interupt(void);
    9. sbit en_ADC = ADC0CN^7;
    10. unsigned int temp;
    11. void main (void)
    12. {
    13.     init_clock();
    14.     init_UART();
    15.     init_tempSensor();
    16.     init_ADC();
    17.     EA = 1;
    18.     en_ADC = 1;    //enable ADC0
    19.     while(1);
    20. }
    21.  
    22. void init_clock(void)
    23. {
    24.      CLKSEL = 0;             //Selects internal clock
    25.      OSCICL = 0;             //clear the internal clock calibration
    26.      OSCICN = 0x83;         //System Clock is devided by 1. SYSCLOCK  = 12MHZ
    27. }
    28.  
    29.  
    30. //Baudrate is 9615
    31. void init_UART(void)
    32. {
    33.      CKCON = 0x01;             //Configure prescaled bits to devide the system clock by 4.
    34.     SCON0 = 0x50;            //RI0 will only be activated if stop bit is logic level 1.
    35.       TMOD = 0x20;            //Timer 1 configured in 8-Bit auto reload
    36.       TH1 = 100;                //TH1 reload value
    37.      TR1 = 1;                //Timer 1 start
    38.      TI0 = 1;                //Transmit Interupt of UART is enabled
    39. }
    40.  
    41. void init_tempSensor(void)
    42. {
    43.      REF0CN = 0x07;           //Enable temp sensor, analogue bias generator, internal voltage reference is used.
    44. }
    45.  
    46. void init_ADC(void)
    47. {
    48.     ADC0CF = 0x1C;          //Configure SAR Conversion clock and left justify configuration for ADC0
    49.     ADC0CN = 0x10;         //ADC0 in Lower Power Mode,Normal Track Mode,ADCBUSY bit is set.
    50.     AMX0P = 0x1E;         //ADC0 Positive Input is In Chip Temp Sensor
    51.     AMX0N = 0x1F;          //ADC0 Negative Input is ground, also know as being configured in Single Ended Mode
    52.     EIE1 = 0x08;           //Enable ADC interrupt when a conversion is complete
    53.        
    54. }
    55.  
    56. void ADC_Interupt(void) interrupt 10
    57. {
    58.      AD0INT = 0;
    59.      temp =  ADC0L + (ADC0H <<8);
    60. }
    61.  
    62.  
     
    Last edited by a moderator: Mar 5, 2011
Loading...