1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need help programing PIC18F14K22

Discussion in 'C' started by Pretendent, May 8, 2013.

  1. Pretendent

    Pretendent New Member

    Joined:
    May 8, 2013
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hello to all
    I have a problem over here :/ here is the point.

    I have a thermometer connected to battery (12v)
    and I need that: when my thermometer reaches 35 celsius it should open the transistor.
    then from the other battery energy flow to the fan

    thermometer code:
    Code:
    #include <p18f14k22.h>
    #pragma config FOSC  = IRC        
    #pragma config WDTEN = OFF  
    #pragma config LVP   = OFF        
    
    const rom unsigned char table_7_segm[]=       
     {
      0x5F, //0
      0x06, //1
      0x3B, //2
      0x2F, //3
      0x66, //4
      0x6D, //5
      0x7D, //6
      0x07, //7
      0x7F, //8
      0x6F, //9
      0x01,      
    };
    
    #pragma code
    
    void delay (unsigned int ms)
    {
    unsigned int i;
    for(i =0 ; i < 332; i++);    
    }
    
    void main (void)
    {
    float skaicius = 0;
    char indikatorius = 0;
    char i = 0;
    	
    
    OSCCONbits.IRCF2 = 1;
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF0 = 1;
    
    ANSEL = 0b0000100;
    ANSELH = 0b0000;
                      
    PORTA = 0;
    TRISA = 0b00100;
    PORTB = 0;
    TRISB = 0;
    PORTC = 0;
    TRISC = 0;
    
    ADCON1 = 0x00;
    ADCON2 = 0b10111101;
    ADCON0 = 0b00001001;
    while (1)
    {
    
    ADCON0bits.GO = 1;
    while (ADCON0bits.GO == 1);
    skaicius = ((unsigned int)ADRESH << 8) |  (unsigned int)ADRESL;
           
    skaicius = skaicius*40.88;
            
    skaicius +=0.5;               
    skaicius = skaicius/1000;
    indikatorius = 0x80;
    for (i=0; i<4; i++) 
    {
    LATC = table_7_segm [(int) (skaicius)]; 
    skaicius = skaicius - (int)skaicius;
    skaicius = skaicius * 10;
    LATB = indikatorius; 
    if(i==1)
    PORTCbits.RC7=1;
                 
    delay(5);
    LATB = 0;
    indikatorius = indikatorius >> 1; 
    }
    }
    
    }
    than you for any help and comments
     

Share This Page