Okay , i doing a project on transmitter system to transmit a signal from one place to another to on light.
But i need help with assembly language using mplab 7.00.
The Transmitting of signal works , but it can only on the LED all the time.
I want to make it to "On" when i press Button, And to "Off" it again when i press button. i was wondering anyone could help me with the code?
Note: Button = Switch
DataOut = 01010101
;This is Trasmitter
list p=12f683 ; list directive to define processor
#include <p12f683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_OFF & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTRC_OSC_NOCLKOUT
__idlocs 0x0001 ; Device Identity Number
; '__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.
;**********************************************************************
; VARIABLE DEFINITIONS (examples)
;**********************************************************************
#define SWITCH GPIO,3 ;RA3 is Connected to a switch
#define D0ON B'11111111' ;Set RA0 as High Voletage and turns LED D0 on
#define D0OFF B'11111110' ;Set RA0 as Low Voletage and turns LED D1 on
#define Header B'10101010'
#define AddrDest b'00000011'
#define AddrSou b'00000001'
#define DataOut b'01010101' ; Data Sent At the LED
#define Instru b'10000000'
#define Bitn B'00001000' ; Number of Bits (16) to be transmitted
#define clip B'0000001'
;**********************************************************************
; Define General Purpose Registers (GRP's)
;**********************************************************************
cblock 0x20
CountO
CountI
Data0
Bitx
endc
;**********************************************************************
; Define Variables
;**********************************************************************
;**********************************************************************
RESET_VECTOR
ORG 0x000 ; processor reset vector
nop
goto init ; goto initialization program
;**********************************************************************
; Interrupts Vector Section
;**********************************************************************
INT_VECTOR
ORG 0x004 ; interrupt vector location
nop
;100*******************************************************************
; isr code can go here or be located as a call subroutine elsewhere
;**********************************************************************
;**********************************************************************
; These first 4 instructions are not required if the internal oscialltor is not used
;**********************************************************************
init
; call 0x3FF ; retrieve factory calibration value
;**********************************************************************
;Bank 1:- OSCAL, TRISIO, & ANSEL Registers Settings
;**********************************************************************
bsf STATUS, RP0 ; set file register bank to 1
movlw B'01100001' ; Run on 4 MHz Internal Clock
movwf OSCCON ; w -> OSCAL update register with factory ca value
movlw b'00001111' ; Run At Maximum Frequency
movwf OSCTUNE
movlw 0x38 ; Set RA0 , RA1 & RA2 as Output Ports
movwf TRISIO ; Configure GPIO as above
clrf INTCON ; Disable all Interupts
clrf PIE1 ; Disable all Interupts
clrf IOC ; Disable all Interupts
clrf ANSEL ^ 0x80 ; Set None Analogue Voltage
movlw b'00000000'
movwf OPTION_REG ; GPIO pull up are enables by individual port latch value
;**********************************************************************
; Bank 0 :- CMCON Registers Settings
;**********************************************************************
bcf STATUS, RP0 ; Set file register bank to 0
movlw 0x007
movwf CMCON0 ; Disable Comparator Inputs & Output
;**********************************************************************
; Main Program Code Goes Here
;**********************************************************************
movlw D0OFF ; Set RA0 At Low Voltage
movwf GPIO
main
btfsc SWITCH ; Wait In Loop until SWITCH closure is sensed
goto main ; SWITCH closure grounds input pin
;**********************************************************************
; Send Out 8 Bits Header Signal
;**********************************************************************
;170*******************************************************************
SendHeader
movlw Header ;Load Data to DataOut
movwf Data0
movlw Bitn ; Number of Bits to be send
movwf Bitx ; Keep Count Of Bits Sent
cont
btfsc Data0, 7 ; Test Bit-7 Status
goto one ; Bit is 0
goto zero ; Bit is 1
zero
call Vzero
goto NextBit
one
call Vone
NextBit
rlf Data0, 1 ; Shift Bit 6 to Bit 7 Location
decfsz Bitx, 1 ;Is it the last Bit, Bit 0?
goto cont ; No, goto next Bit
movlw D0OFF
movwf GPIO
call Delay
;**********************************************************************
; Send Destination Address Btye - 8 Bits
;**********************************************************************
SendDestinationAddr
movlw AddrDest ;Load Data to DataOut
movwf Data0
movlw Bitn ; Number of Bits to be send
movwf Bitx ; Keep Count of Bits sent
cont1
btfsc Data0, 7 ; Test Bit-7 status
goto one1 ;Bit is 0
goto zero1 ;Bit is 1
zero1
call Vzero
goto NextBit1
one1
call Vone
NextBit1
rlf Data0, 1 ;Shift Bit 6 to Bit 7 Location
decfsz Bitx, 1 ; Is it the last Bit, Bit 0?
goto cont1 ; No, Goto Next Bit
movlw D0OFF
movwf GPIO
Call Delay
;**********************************************************************
; Send Source Address Data Byte - 8 Bits
;**********************************************************************
SendSourceAddr
movlw AddrSou ; Load Data to DataOut
movwf Data0
movlw Bitn ; Number Of Bits to be send
movwf Bitx ; Keep Country of Bits sent
cont2
btfsc Data0, 7 ; Test Bit-7 status
goto one2 ; Bit is 0
goto zero2 ; Bit is 1
zero2
call Vzero
goto NextBit2
one2
call Vone
NextBit2
rlf Data0, 1 ; Shift Bit 6 to Bit 7 Location
decfsz Bitx,1 ; Is it the last Bit, Bit 0?
goto cont2 ; No, goto next Bit
movlw D0OFF
movwf GPIO
call Delay
But i need help with assembly language using mplab 7.00.
The Transmitting of signal works , but it can only on the LED all the time.
I want to make it to "On" when i press Button, And to "Off" it again when i press button. i was wondering anyone could help me with the code?
Note: Button = Switch
DataOut = 01010101
;This is Trasmitter
list p=12f683 ; list directive to define processor
#include <p12f683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_OFF & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTRC_OSC_NOCLKOUT
__idlocs 0x0001 ; Device Identity Number
; '__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.
;**********************************************************************
; VARIABLE DEFINITIONS (examples)
;**********************************************************************
#define SWITCH GPIO,3 ;RA3 is Connected to a switch
#define D0ON B'11111111' ;Set RA0 as High Voletage and turns LED D0 on
#define D0OFF B'11111110' ;Set RA0 as Low Voletage and turns LED D1 on
#define Header B'10101010'
#define AddrDest b'00000011'
#define AddrSou b'00000001'
#define DataOut b'01010101' ; Data Sent At the LED
#define Instru b'10000000'
#define Bitn B'00001000' ; Number of Bits (16) to be transmitted
#define clip B'0000001'
;**********************************************************************
; Define General Purpose Registers (GRP's)
;**********************************************************************
cblock 0x20
CountO
CountI
Data0
Bitx
endc
;**********************************************************************
; Define Variables
;**********************************************************************
;**********************************************************************
RESET_VECTOR
ORG 0x000 ; processor reset vector
nop
goto init ; goto initialization program
;**********************************************************************
; Interrupts Vector Section
;**********************************************************************
INT_VECTOR
ORG 0x004 ; interrupt vector location
nop
;100*******************************************************************
; isr code can go here or be located as a call subroutine elsewhere
;**********************************************************************
;**********************************************************************
; These first 4 instructions are not required if the internal oscialltor is not used
;**********************************************************************
init
; call 0x3FF ; retrieve factory calibration value
;**********************************************************************
;Bank 1:- OSCAL, TRISIO, & ANSEL Registers Settings
;**********************************************************************
bsf STATUS, RP0 ; set file register bank to 1
movlw B'01100001' ; Run on 4 MHz Internal Clock
movwf OSCCON ; w -> OSCAL update register with factory ca value
movlw b'00001111' ; Run At Maximum Frequency
movwf OSCTUNE
movlw 0x38 ; Set RA0 , RA1 & RA2 as Output Ports
movwf TRISIO ; Configure GPIO as above
clrf INTCON ; Disable all Interupts
clrf PIE1 ; Disable all Interupts
clrf IOC ; Disable all Interupts
clrf ANSEL ^ 0x80 ; Set None Analogue Voltage
movlw b'00000000'
movwf OPTION_REG ; GPIO pull up are enables by individual port latch value
;**********************************************************************
; Bank 0 :- CMCON Registers Settings
;**********************************************************************
bcf STATUS, RP0 ; Set file register bank to 0
movlw 0x007
movwf CMCON0 ; Disable Comparator Inputs & Output
;**********************************************************************
; Main Program Code Goes Here
;**********************************************************************
movlw D0OFF ; Set RA0 At Low Voltage
movwf GPIO
main
btfsc SWITCH ; Wait In Loop until SWITCH closure is sensed
goto main ; SWITCH closure grounds input pin
;**********************************************************************
; Send Out 8 Bits Header Signal
;**********************************************************************
;170*******************************************************************
SendHeader
movlw Header ;Load Data to DataOut
movwf Data0
movlw Bitn ; Number of Bits to be send
movwf Bitx ; Keep Count Of Bits Sent
cont
btfsc Data0, 7 ; Test Bit-7 Status
goto one ; Bit is 0
goto zero ; Bit is 1
zero
call Vzero
goto NextBit
one
call Vone
NextBit
rlf Data0, 1 ; Shift Bit 6 to Bit 7 Location
decfsz Bitx, 1 ;Is it the last Bit, Bit 0?
goto cont ; No, goto next Bit
movlw D0OFF
movwf GPIO
call Delay
;**********************************************************************
; Send Destination Address Btye - 8 Bits
;**********************************************************************
SendDestinationAddr
movlw AddrDest ;Load Data to DataOut
movwf Data0
movlw Bitn ; Number of Bits to be send
movwf Bitx ; Keep Count of Bits sent
cont1
btfsc Data0, 7 ; Test Bit-7 status
goto one1 ;Bit is 0
goto zero1 ;Bit is 1
zero1
call Vzero
goto NextBit1
one1
call Vone
NextBit1
rlf Data0, 1 ;Shift Bit 6 to Bit 7 Location
decfsz Bitx, 1 ; Is it the last Bit, Bit 0?
goto cont1 ; No, Goto Next Bit
movlw D0OFF
movwf GPIO
Call Delay
;**********************************************************************
; Send Source Address Data Byte - 8 Bits
;**********************************************************************
SendSourceAddr
movlw AddrSou ; Load Data to DataOut
movwf Data0
movlw Bitn ; Number Of Bits to be send
movwf Bitx ; Keep Country of Bits sent
cont2
btfsc Data0, 7 ; Test Bit-7 status
goto one2 ; Bit is 0
goto zero2 ; Bit is 1
zero2
call Vzero
goto NextBit2
one2
call Vone
NextBit2
rlf Data0, 1 ; Shift Bit 6 to Bit 7 Location
decfsz Bitx,1 ; Is it the last Bit, Bit 0?
goto cont2 ; No, goto next Bit
movlw D0OFF
movwf GPIO
call Delay