a Guest
|
can i detect error for one wire error data |
Posted: Wed Dec 22, 2004 11:13 am |
|
|
because i send data from board1 to board2 is data='0xa1' and board2 receive data='0xa0' and sometime receive 0xa1 and how can i check error.
And one question if data from board1 is send. if data is error. board1 or board2 is detect error. i think is board 2 is detected and send error to board1 . Is it right.
below is my source code of board1
===============================================================================
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, float_high, ERRORS, parity=E,xmit=PIN_B0,rcv=PIN_B0,bits=8)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#bit ninth_bit = RS232_ERRORS.7
#bit collision = RS232_ERRORS.6
#bit intf = 11.1
void show_print(char xxdata);
void out_led(char char1);
#define RS PIN_C0
#define RW PIN_C1
#define EN PIN_C2
#define SE1 PIN_A1
#define SE2 PIN_A2
#define CARD_IN !input(PIN_B1)
.....
......
........ other part of program
........
#int_ext
void pbus_isr()
{
BYTE data;
Set_tris_b(0b00000001);
if(kbhit())
{
data=getc();
if(ninth_bit)
{
if(data==0xf2)
{
delay_cycles(1);
}
}
else
{
show_print(data);
wcharxy(2,1,data);
}
}
}
void pbus_write_ram(byte cha)
{
BYTE checksum,i;
retry:
disable_interrupts(GLOBAL);
collision=false;
ninth_bit=0;
putc(cha); if(collision) { goto error; } //0000 1101
out_led(2);
intf=false;
enable_interrupts(GLOBAL);
return;
error:
delay_ms(16);
enable_interrupts(GLOBAL);
goto retry;
}
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8) // Jumpers: 8 to 11, 7 to 12
void show_print(char xxdata)
{
putc(xxdata);
}
#include <input.c>
void main()
{
BYTE to,i,value,cou,sendch;
int CIN;
printf("\r\nPress S to send.\r\n");
port_b_pullups(TRUE);
ext_int_edge( h_to_l );
Set_tris_a(0b000000);
Set_tris_b(0b00000001);
init_lcd();
while(1)
{
if(CARD_IN)
{
delay_ms(250);
IF(CIN==0)
{
OUTPUT_LOW(PIN_A5);
DELAY_MS(10);
OUTPUT_HIGH(PIN_A5);
CIN=1;
}
sendch='ก';
pbus_write_ram(sendch);
hex_to_lcd(1,1,sendch);
delay_ms(500);
pbus_write_ram('ข');
hex_to_lcd(1,1,'ข');
delay_ms(500);
pbus_write_ram('ฃ');
hex_to_lcd(1,1,'ฃ');
delay_ms(500);
pbus_write_ram('ฮ');
hex_to_lcd(1,1,'ฮ');
delay_ms(500);
output_high(PIN_A3);
enable_interrupts(global);
enable_interrupts(int_ext);
}
else
{
disable_interrupts(global);
disable_interrupts(int_ext);
out_led(0x02);
output_low(PIN_A3);
CIN=0;
}
}
}
below is my source code of board2
====================================
#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=3579545)
#use rs232(baud=9600, float_high, ERRORS ,parity=E,xmit=PIN_B7,rcv=PIN_B7,bits=8)
#bit ninth_bit = RS232_ERRORS.7
#bit collision = RS232_ERRORS.6
#bit intf = 11.1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define RW PIN_A0
#define RS PIN_A1
#define EN PIN_A2
#define LED0 PIN_A3
#define LED1 PIN_A4
byte cou;
.......
........
........ other part of program
......
.........
void pbus_write_ram(byte cha)
{
BYTE checksum,i;
retry:
disable_interrupts(GLOBAL);
collision=false;
ninth_bit=1;
out_led(1);
ninth_bit=0;
putc(cha); if(collision) { out_led(3); goto error; } //0000 1101
out_led(2);
intf=false;
enable_interrupts(GLOBAL);
return;
error:
delay_ms(16);
wcharxy(2,5,'E');
enable_interrupts(GLOBAL);
goto retry;
}
#int_RB
void checkserial(void)
{
byte data;
if(kbhit())
{
data=getc(); if(collision) { output_low(PIN_B7); wcharxy(2,3,'E'); }
if(ninth_bit)
{
if(data==0xf2)
{
delay_cycles(1);
}
}
else
{
hex_to_lcd(1,1,data);
}
}
}
#include <input.c>
void main() {
BYTE to,i,value;
port_b_pullups(TRUE);
init_lcd();
ext_int_edge( h_to_l );
enable_interrupts(global);
enable_interrupts(int_ext);
enable_interrupts(int_rb);
enable_interrupts(int_buscol);
while (TRUE)
{
delay_us(1);
}
}
=============
can i detect my error on one wire. please help me. |
|