Help w/Project:12f683 Micro-Controller Transmitter System(MPLAB)

Thread Starter

donutchance

Joined Nov 3, 2008
5
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
 

Thread Starter

donutchance

Joined Nov 3, 2008
5
;**********************************************************************
; Send Data Byte - 8 Bits
;**********************************************************************
SendData
movlw DataOut ;Load Data to DataOut
movwf Data0

movlw Bitn ;Number of Bits to be send.
movwf Bitx ;Keep Count of Bits sent

cont3
btfsc Data0, 7; Test Bit-7 Status
goto one3 ; Bit is 0
goto zero3 ; Bit is 1
zero3
call Vzero
goto NextBit3
one3
call Vone
NextBit3
rlf Data0, 1; Shift Bit 6 to Bit 7 location

decfsz Bitx, 1 ; Is it the last Bit , Bit 0?
goto cont3 ; No, Goto Next Bit

movlw D0OFF
movwf GPIO

call Delay
;**********************************************************************
; Send Instruction Bit - 8 Bits
;**********************************************************************
SendInstru
movlw Instru ;Load Data to DataOut
movwf Data0

movlw Bitn ;Number of Bits to be send
movwf Bitx ;Keep Count of Bit Sent

cont4
btfsc Data0, 7 ;Test Bit-7 Status
goto one4 ;Bit is 0
goto zero4 ;Bit is 1

zero4
call Vzero
goto NextBit4
one4
call Vone
NextBit4
rlf Data0, 1 ;Shift Bit 6 to Bit 7 Location

decfsz Bitx, 1 ;Is it the last bit, bit 0?
goto cont4 ;No,goto, Next Bit

movlw D0OFF
movwf GPIO

call Delay

call Delay
call Delay

goto main ;Yes, Restart the program

;**********************************************************************
; SUBROUTINES Start HERE
;**********************************************************************

;**********************************************************************
; SET RA0 TO High Voltage
;**********************************************************************
Vone
movlw D0ON
movwf GPIO
call Delay
return

;**********************************************************************
; SET RA0 To Low Voltage
;**********************************************************************
Vzero
movlw D0OFF
movwf GPIO
call Delay
return

;**********************************************************************
; Delay Routine
;**********************************************************************
Delay
movlw B'00011000'
movwf CountO
; Start Outer Loop
LoopOut
movlw B'00011000'
movwf CountI
; Start Inner Loop
LoopIn
decfsz CountI,1
goto LoopIn
;End Inner Loop
Decfsz CountO,1
goto LoopOut
;End Outer Loop
Return



;**********************************************************************
; Initialize eeprom Location
;**********************************************************************
END ; directive 'end of program'
 

Thread Starter

donutchance

Joined Nov 3, 2008
5
What i mean is : What will be the code to put at the transmit program. so that when i press the button for the first time , it will send the data "01010101" to the receive program.
When i press 2nd time, It will send " 0000000000" to the receive Rx Program.?
How do i put the code? i wonder . :S
 

beenthere

Joined Apr 20, 2004
15,819
If your external hardware isn't right, then no amount of programming will do a bit of good. What you posted up was not a circuit.
 

Thread Starter

donutchance

Joined Nov 3, 2008
5
the program really works, what i want to do is somehow etra.. could i ask you guyz , How Do you modify the data in dataout? at here #Define DataOut "01010101" to maybe "00001111" in the program. i tried using movwf and then andwf , but it didn't works :/

Any idea how do i modify the DataOut Variable? if i can manage to do that i will solve my program thing
 
Top