' Prozessor ATMega 8 Risc '( Befehle über Com O.ä. Vom Master 2 Byte Befehl Sx + Cr 'S'can x slavenr und prüfsumme slavenr 0 alle Antwort Bei X = Slaveadr Sx + Cr 's'cannen knoten x Ex 'E'rgebnis senden Antwort Bei X = Slaveadr Exwww 'e'rgebnis x + 24 bit Tx 'T'ransmit status daten Antwort Bei X = Slaveadr Txv 't'ransmit 'v'ersion Ab Und Zu Keine Verbindung Zum Slave Interrupt Routinen In Asm Geschrieben Diverses Ausprobiert 8.10.09 14 H Ohne Fehler(8 Slaves) ') 'serielle Komunikation Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'Set Ucsrb.txen Set Ucsrb.rxen 'Ubrrl = 206 '2415.5 Baud '102 4800 Data " W I L L I" 'Ubrrl = 203 '2451 Baud '102 4800 Ubrrl = 206 '2427.2 Baud '102 4800 Ubrrh = 0 On Urxc Rxd_israsm Nosave 'On Utxc Rxd_isr Enable Urxc 'Enable Utxc 'timer 500us ms takt Const Timer0_def = &HFF - 15 Timecount = 0 Config Timer0 = Timer , Prescale = 256 On Ovf0 Tim0_israsm Nosave Timer0 = Timer0_def Enable Timer0 Config Aci = Off , Compare = Off Config Aci = On , Compare = Off Config Watchdog = 1024 '1s Do If Rx_complete = 1 Then Waitms 10 'Beruhigung auf den Bus Result = Rx_data(2) And &H07 If Result = Scannode Then Select Case Rx_data(1) Case "S" : If Scanflag = 0 Then Scanflag = 1 Newscandata = 0 End If Tx_data(1) = "s" Tx_data(2) = Scannode Or &H30 Result = Addchksum(2) Sendflag = 1 Reset Tx_complete Tx_ptr = 0 End If ' result = scannode Reset Rx_complete Rx_ptr = 0 Rx_data(1) = 0 Rx_data(2) = 255 Rx_data(3) = 0 End If 'if rxcomplete If Sendflag = 1 Then If Ucsra.udre = 1 Then 'udre = 1 Then Incr Tx_ptr Result = Tx_data(tx_ptr) If Result = Etx Then If Ucsra.txc = 1 Then 'Waitus 50 'damit der vom empfang auch erkannt wird Sendflag = 0 Set Tx_complete Tx_data(1) = Etx Tx_ptr = 0 Else Decr Tx_ptr End If Else 'Udr = Tx_ptr ' 'reset ByteSend Udr = Tx_data(tx_ptr) End If End If End If Loop $asm Tim0_israsm: push r24 in r24,sreg push r24 'timer neu setzen ldi r24,timer0_def !Out Tcnt0 , R24 'watchdog lds r24,{wdflag} sbrc r24,bit.wdflag wdr cbr r24,2^bit.wdflag stS {wdflag},r24 ' timecount lds r24,{timecount} inc r24 stS {timecount},r24 cpi r24,200 brne tims clr r24 stS {timecount},r24 lds r24,{slowtimer} cpi r24,0 breq tims dec r24 sts {slowtimer},r24 Tims: lds r24,{s_timer} cpi r24,0 breq timt dec r24 sts {s_timer},r24 Timt: lds r24,{timeout_timer} cpi r24,0 breq timend dec r24 sts {timeout_timer},r24 'restore reg Timend: pop r24 !Out Sreg , R24 pop r24 reti Rxd_israsm: ' sbi PORTd,5 push xl push xh Push r23 push r24 in r24,sreg push r24 in r24,ucsra andi r24,24 '00011000b Framing Error Data Overrun Error cpi r24,0 in r24,udr 'byte jedenfalls holen breq rxdok ldi r24,0xaa sts {errorflag},r24 rjmp rxderror Rxdok: sts {intresult},r24 lds r23,{timeout_timer} cpi r23,0 BRNE rxd_isrcont sts {rx_ptr},r23 ;r23 ist 0! 'rxptr = 0 Rxd_isrcont: ldi r23,TIMEOUTDEF '30ms sts {timeout_timer},r23 'timeoutimer =50 lds r23,{sendflag} 'if(sendflag = 0 and txcomplete = 1) bst r23,bit.sendflag BRTS noread 'sendflag = 1 lds r23,{TX_complete} bst r23,bit.tx_complete BRTc noread 'tx_complete = 0 lds r23,{rx_ptr} 'if rxptr>22 cpi r23,22 brcs readchar breq readchar sts {rx_ptr},r23 'rx_ptr = 22 Readchar: inc r23 'rxptr+1 sts {rx_ptr},r23 ' rx_data[rx_ptr] = intresult Loadadr Rx_data(1) , X sbiw xl,1 add xl,r23 clr r23 adc xh,r23 st x,r24 'rx_data[rxptr] = intresult 'if intresult = CR cpi r24,CR brne no_cr Loadadr Rx_data(2) , X ld r23,x ' !out udr,r23 andi r23,07 lds r24,{scannode} cp r24,r23 brne nonode 'debug ' Waitus 500 lds r24,{rx_complete} sbr r24,2^bit.rx_complete sts {rx_complete},r24 rjmp Rxd_end Nonode: Rxderror: Loadadr Rx_data(1) , X sbiw xl,1 clr r23 st x,r23 sts {rx_ptr},r23 No_cr: Noread: 'restore reg Rxd_end: pop r24 !Out Sreg , R24 pop r24 pop r23 pop xh pop xl ' cbi portd,5 reti $end Asm