void main() { int H=0; int B=0; int i=0; int16 temp_value1 = 0; int16 temp_value2 = 0; int16 Temperature; int8 parity; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_spi(FALSE); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); lcd_init(); lcd_gotoxy(1,1); printf(lcd_putc,"TSIC 206 Test!"); lcd_gotoxy(1,2); ////////////////////////////// while(1) { temp_value1=0; Temperature=0; delay_ms(500); output_high(PIN_C0); delay_us(120); while (input(Pin_A0)); // wait until start bit starts // wait, TStrobe while (!input(Pin_A0)); // first data byte // read 8 data bits and 1 parity bit for (i = 0; i < 9; i++) { while (input(Pin_A0)); // wait for falling edge delay_us(60); if (input(Pin_A0)) temp_value1 |= 1 << (8-i); // get the bit else while (!input(Pin_A0)); // wait until line comes high again } temp_value2=0; // second byte while (input(Pin_A0)); // wait, TStrobe while (!input(Pin_A0)); // read 8 data bits and 1 parity bit for (i = 0; i < 9; i++) { while (input(Pin_A0)); // wait for falling edge delay_us(60); if (input(Pin_A0)) temp_value2 |= 1 << (8-i); // get the bit else while (!input(Pin_A0)); // wait until line comes high again } output_low(PIN_C0); // switch TSic off // check parity for byte 1 parity = 0; for (i = 0; i < 9; i++) if (temp_value1 & (1 << i)) parity++; if (parity % 2){H=0;} // check parity for byte 2 parity = 0; for (i = 0; i < 9; i++) if (temp_value2 & (1 << i)) parity++; if (parity % 2){B=0;} temp_value1 >>= 1; // delete parity bit temp_value2 >>= 1; // delete parity bit Temperature = (temp_value1 << 8) | temp_value2; lcd_gotoxy(1,4); printf(lcd_putc,"Parity:_%d_%d",H,B);//0 means FAIL H=1; B=1; T=((float)Temperature/2047*200)-50; lcd_gotoxy(1,2); printf(lcd_putc,"D: %ld",Temperature); lcd_gotoxy(1,3); printf(lcd_putc,"T: %f",T); } }