Dock blir det ju lite moment 22 att skriva kod för både sändare och mottagare och sen felsöka, för fel blir det ju tyvärr alltid i början..
Så jag skulle vilja ha hjälp med att se över min sändarkod så jag kan gå vidare med att fixa mottagarsidan.
Vad tror ni om det här: (Ser det något åt rätt håll ut!?)
Kod: Markera allt
;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F628A. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F628A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=16f628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
; Variabel Defenitioner
w_temp RES 1
status_temp RES 1
indata RES 1
d1 RES 1
d2 RES 1
d2 RES 1
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
call setup_pic
call setup_usart
loop
call read_data
call delay
call send_data
call delay
goto loop
; remaining code goes here
;inställning av processorn
setup_pic
banksel ansel ; Stäng av alla analoga funktioner
clrf ansel
banksel trisa ; Alla pinnar utgångar...
movlw ox1f ;Port A 0:4 som ingångar
movwf trisa ;...
clrf trisb
banksel intcon
clrf intcon
banksel porta
; inställning av USART
setup_usart
banksel SPBRG
movlw h40
movwf SPBRG
banksel TXSTA
movlw h24
movwf TXSTA
banksel RCSTA
movlw h90
movwf RCSTA
return
;Inläsning av data på port A
read_data
movf PORTA
movwf indata
return
;sändning av data
send_data
movf indata
banksel TXREG
movwf TXREG
return
; Delay = 1 seconds
; Clock frequency = 20 MHz
; Actual delay = 1 seconds = 5000000 cycles
; Error = 0 %
Delay
;4999993 cycles
movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
; initialize eeprom locations
ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03
END ; directive 'end of program'