#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Need help programing PIC18F14K22


    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

    sorry for my poor eng. here is the scheme of my idea if u dont get it:
    http://ikelk.lt/i/134796/o_5a9423df82.jpg

    thermometer principal scheme:
    http://ikelk.lt/i/134788/o_24a178da5a.jpg

    thermometer PCB scheme:
    http://ikelk.lt/i/134789/o_37e587e6c2.jpg

    and if you dont know how transistors working:
    http://www.youtube.com/watch?v=ZaBLiciesOU

    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
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo