Visst kan jag fortsätta skriva om vad jag gör framöver.
Vet inte vad jag kommer köra för typ av program/OS än. Är inte någon mästare på just programmering tycker jag.
Det blir nog en del i taget, så får jag se hur man kan bygga ihop det sedan.
Jag läste just assembler för mikrodatorer när jag studerade, så det är det jag fortsatt med nu.
C/C++ är nog bättre, så jag överväger om jag skall lära mig det.
Så här blev förresten schemat på det jag gjorde för att öppna can nätet
Och om det finns någon intresserad så har jag programmet jag gjorde för mikroprocessorn (PIC12F675) här.
Allt gjort i microchip's egna miljö, MPLAB IDE.
Som sagt så är jag inte bäst på programmering, så det kunde säkert gjorts på något bättre sätt.
Nästa gång använder jag nog en processor med inbyggd UART, så blir det mycket enklare.
Mina kommentarer flyttade sig lite i sidled när jag kopierade.
Kod: Markera allt list p=12f675
#include P12f675.inc
__config 0x3F94 ;Internal Osc no clk out, WDT off, PUT off, MCLRE internal, BODEN off, CP off, CPD off
;Create variables in RAM area, starting at 0x20
sendbyte EQU 0x20 ;Byte ready to send
bit_count EQU 0x21 ;Counter to keep track of which bit in "sendbyte" is beeing transmitted
byte_count EQU 0x22 ;Counter to keep track of which byte is beeing sent
delay_1 EQU 0x23 ;Delay each bit to establish 10,4k baud
ready_to_send EQU 0x24 ;Used to create delay between sends, ~2sec
org 0x00 ;Reset vektor
goto main
org 0x04 ;Start of Interrupt routine
BTFSC PIR1,TMR1IF ;Check if Timer1 interrupt has occured
GOTO tmr1_int
retfie
main:
;-----------------------Start init-----------------------
call 0x3FF ; retrieve factory calibration value for internal oscillator
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bsf PIE1,T1IE ;TMR1 interrupt enable
bsf INTCON,PEIE ;Enable all perpheral interrupt (TMR1)
bcf INTCON,T0IE ;TMR0 interrupt disable
BSF INTCON,GIE ;Interrupt enable
movlw 0x00
movwf ANSEL
clrf TRISIO ;Set all pins to output (except GP3/MCLR)
bcf STATUS,RP0
movlw B'00110001'
movwf T1CON ;Setup Timer1, prescler 1:8, int.osc., enabled
clrf GPIO ;Disable all A/D and comparators
movlw 0x07 ;All pins digital I/O
movwf CMCON
call delay
call delay ;Delay to make Tx-line idle (+12V)
;------------------ Init Done---------------------------
clrf byte_count
load_byte:
movf byte_count,W ;Load actual table position in work
call table ;Load "sendbyte" with data from table
movwf sendbyte
call uart ;Send "sendbyte"
incf byte_count,F ;Prepare to load next byte
btfss byte_count,2
goto load_byte
btfss byte_count,1 ;Check to se that all bytes are sent
goto load_byte ;If not go back to "load_byte", to continue with next
btfss byte_count,0
goto load_byte ;Else goto "end_loop" to wait for next transmission
clrf byte_count
goto end_loop
end_loop:
btfss ready_to_send,2
goto end_loop ;Loop to create 2sek delay after each transmission
goto load_byte ;Uses Timer1 to create interrupt which increases ready_to_send
;-----------Uart, sends bits located in "sendbyte" register using 8N1 transmission---------
uart:
clrf ready_to_send
movlw 0x09 ;Ready to send 8bits, (use nr of bits + 1)
movwf bit_count
start_bit:
bsf GPIO,GP0 ;Startbit = '0V', transistor connected to pin
nop ;will reverse polarity
nop ;so GP0 = '1' --> 0V
nop ;GP0 = '0' --> 12V
nop
nop
start_byte:
call delay
decfsz bit_count,F ;If all bits sent proceed to send stop bit
goto send_bit ;Else send next bit
stopp_bit:
nop
nop ;nop used to keep delay of 96us between each bit
nop
nop
bcf GPIO,GP0 ;Stoppbit = '1'
call delay
return
send_bit: ;Send bit from last position of sendbyte register
btfsc sendbyte,0
goto send_1
nop
send_0:
bsf GPIO,GP0
goto return_sendbit
send_1:
bcf GPIO,GP0
goto return_sendbit
return_sendbit
rrf sendbyte,F ;Then rotate right to allow for transmission of next bit
goto start_byte
delay: ;Hardcoded Delay used to create 10400 baud
movlw 0x1A ;This is made with regard to the uart above
movwf delay_1 ;Total delay between each bit should be 96uS = 96 instruction cycles at 4MHz clockspeed
delay_loop:
decfsz delay_1,F
goto delay_loop
nop
return
tmr1_int: ;Timer1 interrupt routine
incf ready_to_send,F ;Increase counter for delay between tranmissions
bcf PIR1,TMR1IF ;Clear interrupt flag for TMR1
retfie
table: ;Table containing bytes to send.
addwf PCL,F
retlw 0x84
retlw 0x40
retlw 0x13
retlw 0xb2
retlw 0xf0
retlw 0x03
retlw 0x7c
org 0x3ff ;Oscillator calibration value.
retlw 0x94 ;!! Please check your value by reading your PIC before programming
end ;Then change this value to match your processor.