00001
00002
00003
00004
00005 #include "piccolo_all.h"
00006 #include "piccolo_i2c.h"
00007
00021
00022 #if defined(USE_INTERRUPT)
00023 #error "Nem kell definiálni az USE__INTERRUPT szimbólumot!"
00024 #endif //USE_INTERRUPT
00025 #if !defined(USE_USB)
00026 #error "Nincs definiálva az USE_USB szimbólum!"
00027 #endif //USE_USB
00028
00029
00033 void LM75_init(uint8 addr) {
00034 i2c_start();
00035 i2c_putc(addr & 0xFE);
00036 i2c_putc(0x01);
00037 i2c_putc(0x18);
00038 i2c_stop();
00039 }
00040
00046 int LM75_readTemp(uint8 addr) {
00047 union16 temp;
00048 i2c_start();
00049 i2c_putc(addr & 0xFE);
00050 i2c_putc(0x00);
00051 i2c_rstart();
00052 i2c_putc(addr | 0x01);
00053 temp.hi_byte=i2c_getc(I2C_ACK);
00054 temp.lo_byte=i2c_getc(I2C_NAK);
00055 i2c_stop();
00056 return ((int16)temp.word);
00057 }
00058
00059 void main(void) {
00060 int16 temp;
00061 int32 tmp32;
00062 InitializeSystem();
00063 while (!usb_cdc_kbhit()) {
00064 ProcessIO();
00065 }
00066 i2c_init(100);
00067 LM75_init(0x90);
00068 outString("\nIsten hozott a PICCOLO projekthez!\n");
00069 outString("LM75_i2c.c program, MCU: ");
00070 #if defined(__18F4550)
00071 outString("PIC18F4550\n");
00072 #elif defined(__18F14K50)
00073 outString("PIC18F14K50\n");
00074 #endif
00075 while (1) {
00076 delay_ms(2000);
00077 temp=LM75_readTemp(0x90);
00078 outString("T1 = ");
00079 tmp32=(temp*10L+128L)/256;
00080 outdec(tmp32,1);
00081 outString(" C (0x");
00082 out4hex((uint16)temp);
00083 outString(")\n");
00084 }
00085 }