M
member_tdh
Guest
Hallo alle leden!
In mijn project wil ik verzonden gegevens tussen 2 AVR via RS232.Ik gebruik van CRC-algoritme te gecorrigeerde gegevens, maar mijn programma draait verkeerd.Ik heb geen begrip voor detail over CRC methode nog niet.Post ik mijn code ontvangen en transmition, iemand help me pls ...!?
Dankzij alle vrienden!
/ / Dit
is Transmit Data routine:
/************************************************* ****
Chip type: ATmega8515
Soort programma: Toepassing
Klokfrequentie: 8.000000 MHz
Memory model: Kleine
Externe SRAM grootte: 0
Gegevens Stack size: 128
************************************************** *** /
#
include <mega8515.h>
#
include <delay.h>
#
include <stdlib.h>
/ / Standard Input / output functies
#
include <stdio.h>
# define BYTE unsigned char
# define WOORD unsigned int
void init ();
BYTE DiemGui, ViTriLed;
WORD msec;
bits bTransToPc = 0;
interrupt [TIM1_OVF] nietig timer1_ovf_isr (void)
(
TCNT1H = 0xFF; / / onderbreken 1ms
TCNT1L = 0x83;
if ( msec == 1000)
(
msec = 0;
if ( DiemGui> 10) DiemGui = 5;
if ( ViTriLed> 6) ViTriLed = 1;
bTransToPc = 1;
/ / Putchar ( 'B');
/ / Putchar (DiemGui);
/ / Putchar (ViTriLed);
)
)void init ()
(
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF;
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0xFF;
PORTE = 0xFF;
DDRE = 0xFF;
/ / Timer / Counter 1 initialisatie
/ / Clock source: System Clock
/ / Klok waarde: 125.000 kHz
/ / Mode: Normal top = FFFFh
/ / OC1A output: Discon.
/ / OC1B output: Discon.
/ / Ruis Canceler: Off
/ / Input Capture op Falling Edge
/ / Timer 1 Overflow Interrupt: On
/ / Input Capture Interrupt: Off
/ / Compare A Match Interrupt: Off
/ / Vergelijk B Match Interrupt: Off
TCCR1A = 0x00;
TCCR1B = 0x03;
TCNT1H = 0x00;
TCNT1L = 0x00;
ICR1H = 0x00;
ICR1L = 0x00;
OCR1AH = 0x00;
OCR1AL = 0x00;
OCR1BH = 0x00;
OCR1BL = 0x00;
/ / Timer (s) / Counter (s) Interrupt (s) initialisatie
TIMSK = 0x80;
/ / USART initialisatie
/ / Communicatie Parameters: 8 databits, 1 stop, geen pariteit
/ / USART Receiver: On
/ / USART Transmitter: On
/ / USART Mode: Asynchrone
/ / USART Baudrate: 9600
UCSRA = 0x00;
UCSRB = 0x18;
UCSRC = 0x86;
UBRRH = 0x00;
UBRRL = 0x33;
/ / Global interrupts inschakelen
# asm ( "sei")
)
/ / Declareer uw globale variabelen hier
void main (void)
(
BYTE B1, B2, B3, B4, checksum;
Init ();
ViTriLed = 1;
DiemGui = 5;while (1)
(
b1 = (DiemGui% 10) 0 X30;
b2 = (DiemGui/10) 0 X30;
B3 = (ViTriLed% 10) 0 X30;
b4 = (ViTriLed/10) 0 X30;
checksum = b1 ^ b2 ^ B3 ^ b4;
putchar ( 'B');
putchar (B1);
putchar (B2);
putchar (B3);
putchar (B4);
putchar (checksum);
);
)/ / Dit
is ontvangen gegevens routine:
BYTE buffer [10];
void main ()
(
BYTE i, crc8;
Init ();
/ / ontvangen 5-Bytes
for (i = 0; i <5; i ) crc8 = crc8_calc (buffer, 5);
while (1)
()
)BYTE crc8_calc (BYTE * být, WORD-formaat)
(
/ * Bereken CRC-8 waarde; gebruikt de CCITT-8 polynoom,
uitgedrukt als x ^ 8 x ^ 5 x ^ 4 1 * /
BYTE CRC = (BYTE) 0xff;
WORD index;
Byte b;
for (index = 0; index <grootte; index )
(
CRC ^ = být [index];
voor (b = 0; b <8; b)
(
if (CRC & 0x80)
CRC = (CRC <<1) ^ 0x31;
anders
CRC = (CRC <<1);
)
)
terugkeer CRC;
)
Pls iemand uitleggen hoe wordt CRC8 werk ...?
Bedankt allemaal!
In mijn project wil ik verzonden gegevens tussen 2 AVR via RS232.Ik gebruik van CRC-algoritme te gecorrigeerde gegevens, maar mijn programma draait verkeerd.Ik heb geen begrip voor detail over CRC methode nog niet.Post ik mijn code ontvangen en transmition, iemand help me pls ...!?
Dankzij alle vrienden!
/ / Dit
is Transmit Data routine:
/************************************************* ****
Chip type: ATmega8515
Soort programma: Toepassing
Klokfrequentie: 8.000000 MHz
Memory model: Kleine
Externe SRAM grootte: 0
Gegevens Stack size: 128
************************************************** *** /
#
include <mega8515.h>
#
include <delay.h>
#
include <stdlib.h>
/ / Standard Input / output functies
#
include <stdio.h>
# define BYTE unsigned char
# define WOORD unsigned int
void init ();
BYTE DiemGui, ViTriLed;
WORD msec;
bits bTransToPc = 0;
interrupt [TIM1_OVF] nietig timer1_ovf_isr (void)
(
TCNT1H = 0xFF; / / onderbreken 1ms
TCNT1L = 0x83;
if ( msec == 1000)
(
msec = 0;
if ( DiemGui> 10) DiemGui = 5;
if ( ViTriLed> 6) ViTriLed = 1;
bTransToPc = 1;
/ / Putchar ( 'B');
/ / Putchar (DiemGui);
/ / Putchar (ViTriLed);
)
)void init ()
(
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF;
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0xFF;
PORTE = 0xFF;
DDRE = 0xFF;
/ / Timer / Counter 1 initialisatie
/ / Clock source: System Clock
/ / Klok waarde: 125.000 kHz
/ / Mode: Normal top = FFFFh
/ / OC1A output: Discon.
/ / OC1B output: Discon.
/ / Ruis Canceler: Off
/ / Input Capture op Falling Edge
/ / Timer 1 Overflow Interrupt: On
/ / Input Capture Interrupt: Off
/ / Compare A Match Interrupt: Off
/ / Vergelijk B Match Interrupt: Off
TCCR1A = 0x00;
TCCR1B = 0x03;
TCNT1H = 0x00;
TCNT1L = 0x00;
ICR1H = 0x00;
ICR1L = 0x00;
OCR1AH = 0x00;
OCR1AL = 0x00;
OCR1BH = 0x00;
OCR1BL = 0x00;
/ / Timer (s) / Counter (s) Interrupt (s) initialisatie
TIMSK = 0x80;
/ / USART initialisatie
/ / Communicatie Parameters: 8 databits, 1 stop, geen pariteit
/ / USART Receiver: On
/ / USART Transmitter: On
/ / USART Mode: Asynchrone
/ / USART Baudrate: 9600
UCSRA = 0x00;
UCSRB = 0x18;
UCSRC = 0x86;
UBRRH = 0x00;
UBRRL = 0x33;
/ / Global interrupts inschakelen
# asm ( "sei")
)
/ / Declareer uw globale variabelen hier
void main (void)
(
BYTE B1, B2, B3, B4, checksum;
Init ();
ViTriLed = 1;
DiemGui = 5;while (1)
(
b1 = (DiemGui% 10) 0 X30;
b2 = (DiemGui/10) 0 X30;
B3 = (ViTriLed% 10) 0 X30;
b4 = (ViTriLed/10) 0 X30;
checksum = b1 ^ b2 ^ B3 ^ b4;
putchar ( 'B');
putchar (B1);
putchar (B2);
putchar (B3);
putchar (B4);
putchar (checksum);
);
)/ / Dit
is ontvangen gegevens routine:
BYTE buffer [10];
void main ()
(
BYTE i, crc8;
Init ();
/ / ontvangen 5-Bytes
for (i = 0; i <5; i ) crc8 = crc8_calc (buffer, 5);
while (1)
()
)BYTE crc8_calc (BYTE * být, WORD-formaat)
(
/ * Bereken CRC-8 waarde; gebruikt de CCITT-8 polynoom,
uitgedrukt als x ^ 8 x ^ 5 x ^ 4 1 * /
BYTE CRC = (BYTE) 0xff;
WORD index;
Byte b;
for (index = 0; index <grootte; index )
(
CRC ^ = být [index];
voor (b = 0; b <8; b)
(
if (CRC & 0x80)
CRC = (CRC <<1) ^ 0x31;
anders
CRC = (CRC <<1);
)
)
terugkeer CRC;
)
Pls iemand uitleggen hoe wordt CRC8 werk ...?
Bedankt allemaal!