Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

temp sensor problem in mikro c pro

Status
Not open for further replies.

newbie111

Member level 2
Joined
Nov 29, 2009
Messages
51
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
h.k
Activity points
1,609
hi folks

i am using 16f690 8 m external osc compile everything with mikro c pro

i followed the examples and made this temp logger
everything worked out
*****************


i have been trying to write some codes to turn off the led on portc.7
when a certain degree is reached (let's say led goes off when it is 20 degrees)

but
i failed to do so

if anyone knows how to make it, pls kindly teach me

Thank you so much in advance





Code:
sbit LCD_RS at Rc4_bit;
sbit LCD_EN at Rc5_bit;
sbit LCD_D4 at Rc0_bit;
sbit LCD_D5 at Rc1_bit;
sbit LCD_D6 at Rc2_bit;
sbit LCD_D7 at Rc3_bit;

sbit LCD_RS_Direction at TRISc4_bit;
sbit LCD_EN_Direction at TRISc5_bit;
sbit LCD_D4_Direction at TRISc0_bit;
sbit LCD_D5_Direction at TRISc1_bit;
sbit LCD_D6_Direction at TRISc2_bit;
sbit LCD_D7_Direction at TRISc3_bit;



const unsigned short TEMP_RESOLUTION = 12;

char *text = "000.0000";

unsigned temp;


void Display_Temperature(unsigned int temp2write) {
  const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
  char temp_whole;
  unsigned int temp_fraction;
  


  

if (temp2write & 0x8000) {
    text[0] = '-';
    temp2write = ~temp2write + 1;
  }






  temp_whole = temp2write >> RES_SHIFT ;


  if (temp_whole/100)
     text[0] = (temp_whole/100)  + 48;
          else

                    text[0] = '0';









  text[1] = (temp_whole/10)%10 + 48;

  
  text[2] =  temp_whole%10     + 48;
  

    


  temp_fraction  = temp2write << (4-RES_SHIFT);
  temp_fraction &= 0x000F;
  temp_fraction *= 625;
  




  text[4] =  temp_fraction/1000    + 48;         // Extract thousands digit
  text[5] = (temp_fraction/100)%10 + 48;         // Extract hundreds digit
  text[6] = (temp_fraction/10)%10  + 48;         // Extract tens digit
  text[7] =  temp_fraction%10      + 48;         // Extract ones digit


  

  
  
  
  Lcd_Out(2, 5, text);
  


  UART1_Write(10);
  UART1_Write(13);
  UART1_Write_Text("Current temp: ");
  UART1_Write_Text (text);
  delay_ms(2000);


      
}

void main() {
    ANSEL  = 0;
  ANSELH = 0;
  C1ON_bit = 0;
  C2ON_bit = 0;
  trisc=0x00;
    portc.B7=1;
 Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1, 1, " Temperature: ");

  Lcd_Chr(2,13,223);


  Lcd_Chr(2,14,'C');
UART1_Init(9600);
Delay_ms(100);


  do {

    Ow_Reset(&PORTa, 2);                         // Onewire reset signal
    Ow_Write(&PORTa, 2, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTa, 2, 0x44);                   // Issue command CONVERT_T
    Delay_us(120);

    Ow_Reset(&PORTa, 2);
    Ow_Write(&PORTa, 2, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTa, 2, 0xBE);                   // Issue command READ_SCRATCHPAD

    temp =  Ow_Read(&PORTa, 2);
    temp = (Ow_Read(&PORTa, 2) << 8) + temp;

    //--- Format and display result on Lcd
    Display_Temperature(temp);

    Delay_ms(500);

 } while (1);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top