/* Main.c file generated by New Project wizard
 *
 * Created:   H okt. 19 2015
 * Processor: PIC18LF46K22
 * Compiler:  MPLAB C18
 */

#include <p18LF46K22.h>
#include "config.h"
#include <delays.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.c"
#include "ds1820.h"

void init(void);

void main(){ 
	unsigned char buf[20] = {0};
	int tempe;
	
	init();
	lcd_init();

	while(1){
	
		OW_RESET();
		DSTXBYTE(0xCC);
		DSTXBYTE(0x44);
		for(i=750; i==0; i--) Delay10KTCYx(16);
		OW_RESET();
		DSTXBYTE(0xCC);
		DSTXBYTE(0xBE);
		tempe = DSRXBYTE();
		tempe += (DSRXBYTE() << 8);
	
		itoa(tempe, buf);
		
		printf("DS18B20 szenzor     ");
		lcd_write(0xC0,0,1,1);   
		printf("Teszt               ");
		lcd_write(0x94,0,1,1);
		printf("Adat i:%i           ", tempe);
		lcd_write(0xD4,0,1,1);
		printf("Adat s:%s           ", buf);
		lcd_write(0x80,0,1,1);	
	
		Delay10KTCYx(255);
	}
	   
 }//main

 void init(void){

    /*********************************************
	+		Ki / Bemenetek
	**********************************************/
	TRISA = 0;
	PORTA = 0;
	TRISD = 0;
	PORTD = 0;	
	TRISB = 0;
	PORTB = 0;
	TRISE = 0;
	PORTE = 0;
	TRISC = 0;		// PWM portok és egyébbek, teljes port kimenetre állítva
	PORTC = 0;
	
	ADCON0 = 0;		// ADC le van tiltva
	ADCON1 = 0;
	ADCON2 = 0;
	
	CM2CON1 = 0;
	CM1CON0 = 0;
	CM2CON0 = 0;
	
	ANSELA = 0;		// Digital input buffer enabled
	ANSELB = 0;
	ANSELC = 0;
	ANSELD = 0;
	ANSELE = 0;
	
	OSCCON = 0; 	// Primary Clock-ot használjuk CONFIG1H beállításai szerint
    OSCCON2 = 0x04; // Oscillator drive circuit on
    OSCTUNE = 0x20; // PLL enabled
	
	CCP1CON = 0;	// Coperátorok és PWM kikapcsolva
	CCP2CON = 0;
	CCP3CON = 0;
	CCP4CON = 0;
	CCP5CON = 0; 
}
