;************************************* ; Author : Mike Baird ; Program : Wireless Tx ; Date : December 27th, 2009 ;************************************* List P=16F88 #include "P16F88.INC" __CONFIG _CONFIG1, _PWRTE_ON & _WDT_OFF & _INTRC_IO & _BODEN_OFF & _LVP_OFF & _CP_OFF & _MCLR_OFF __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF ;*** Defines *** packet_len EQU 5 ;packet length 4 + 1 address byte #ifndef TXINV #define TXLOW BCF PORTB, 0 ;TX pin is portb, 0 #define TXHIGH BSF PORTB, 0 #else #define TXLOW BSF PORTB, 0 #define TXHIGH BCF PORTB, 0 #endif ;*** Variable Declerations *** CBLOCK 0x20 ncnt bt sum mtx_buffer mtx_buffer1 mtx_buffer2 mtx_buffer3 mtx_buffer4 mtx_delay ; half_frame delay Count1 ; For delay! Count2 CountA ; CountB ; ENDC ;*** Start of Program *** ORG 0x00 GOTO Start ORG 0x04 RETFIE ;*** Configuration *** Start: CLRF PORTA ; PortA all low CLRF PORTB ; PortB all low BSF STATUS,RP0 ; Bank 1 MOVLW b'01100000' ; Make clock 4Mhz IORWF OSCCON ; MOVLW b'00000000' ; Bit 5 input MOVWF TRISA ; PortA all output except MCLR CLRF TRISB ; PortB all output CLRF ANSEL ; Make PORTA all digital I/O BCF STATUS,RP0 ; Bank 0 Call mtx_init ;*** Main Program *** Main: MOVLW 0xAA ;set packet address byte to 0xAA MOVWF mtx_buffer MOVLW 'E' ;set four bytes in buffer MOVWF mtx_buffer1 MOVLW 'l' MOVWF mtx_buffer2 MOVLW 'e' MOVWF mtx_buffer3 MOVLW 'c' MOVWF mtx_buffer4 Call mtx_send ;send all four bytes in one packet Call Delay20 MOVLW 't' ;set four bytes in buffer MOVWF mtx_buffer1 MOVLW 'r' MOVWF mtx_buffer2 MOVLW 'o' MOVWF mtx_buffer3 MOVLW 'b' MOVWF mtx_buffer4 Call mtx_send ;send all four bytes in one packet Call Delay20 MOVLW 'i' ;set four bytes in buffer MOVWF mtx_buffer1 MOVLW 'r' MOVWF mtx_buffer2 MOVLW 'd' MOVWF mtx_buffer3 MOVLW '!' MOVWF mtx_buffer4 Call mtx_send ;send all four bytes in one packet GOTO $ ;*** Manchester Subroutines *** ; Author: el@jap.hu ; http://jap.hu/electronic/ mtx_init MOVLW .115 ; 350 usec MOVWF mtx_delay RETURN mtx_send outbuf MOVLW 0x14 ; 20xbit1, 1xbit0 header MOVWF Count2 head0 Call bit1 DECFSZ Count2,F GOTO head0 Call bit0 MOVLW mtx_buffer MOVWF FSR MOVLW packet_len MOVWF Count1 MOVLW 0xFF MOVWF sum outbu0 MOVF INDF,W Call update_sum MOVF INDF,W Call outbyte INCF FSR,F DECFSZ Count1,F GOTO outbu0 MOVF sum,W Call outbyte RETURN ; buffer is sent update_sum ; fast CRC-8 algorithm with poly x^8+x^5+x^4+1 XORWF sum,f ; executes in 23 cycles per update CLRW BTFSC sum,7 XORLW 0x7A BTFSC sum,6 XORLW 0x3D BTFSC sum,5 XORLW 0x86 BTFSC sum,4 XORLW 0x43 BTFSC sum,3 XORLW 0xB9 BTFSC sum,2 XORLW 0xC4 BTFSC sum,1 XORLW 0x62 BTFSC sum,0 XORLW 0x31 MOVWF sum RETURN outbyte MOVWF bt MOVLW .8 MOVWF Count2 outby0 RLF bt,F BTFSC STATUS,C GOTO outby1 Call bit0 GOTO outby2 outby1 Call bit1 outby2 DECFSZ Count2,F Goto outby0 Call bit1 ; and bit0 - falls through to bit0 subroutine bit0 ;send a bit0 TXHIGH ; HIGH Call mtx_bitdel ; bit time delay TXLOW ; to LOW transition Call mtx_bitdel ; bit time delay RETURN bit1 ;send a bit1 TXLOW ; LOW Call mtx_bitdel ; bit time delay TXHIGH ; to HIGH transition Call mtx_bitdel ; bit time delay RETURN ; bit delay modified by NG mtx_bitdel MOVF mtx_delay,W MOVWF ncnt ndelaya1 DECFSZ ncnt, F GOTO ndelaya1 RETURN ;*** End of Manchester Routines*** ;*** Delay Routines *** Delay255 MOVLW d'255' ; Delay 255 mS GOTO d0 Delay100 MOVLW d'100' ; Delay 100mS GOTO d0 Delay50 MOVLW d'50' ; Delay 50mS GOTO d0 Delay20 MOVLW d'20' ; Delay 20mS GOTO d0 Delay5 MOVLW d'5' ; Delay 5.000 ms (4 MHz clock) d0 MOVWF Count1 d1 MOVLW 0xC7 ; Delay 1mS MOVWF CountA MOVLW 0x01 MOVWF CountB Delay_0 DECFSZ CountA,F GOTO $+2 DECFSZ CountB,F GOTO Delay_0 DECFSZ Count1,F GOTO d1 RETURN END