All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Programmer's Corner

Notices

Programmer's Corner Discussion forum for all aspects of programming and software engineering. Any software programming language welcome: C, C++, C#, Fortran, Java, Matlab, etc.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 11-04-2008, 01:23 AM
donutchance donutchance is offline
New Member
 
Join Date: Nov 2008
Location: Singapore
Posts: 5
Unhappy Help w/Project:12f683 Micro-Controller Transmitter System(MPLAB)

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
Reply With Quote
  #2  
Old 11-04-2008, 01:24 AM
donutchance donutchance is offline
New Member
 
Join Date: Nov 2008
Location: Singapore
Posts: 5
Default Repeat

;************************************************* *********************
; 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'
Reply With Quote
  #3  
Old 11-05-2008, 01:35 AM
beenthere's Avatar
beenthere beenthere is offline
Senior Member
 
Join Date: Apr 2004
Location: Missouri, USA (GMT -6)
Posts: 15,815
Blog Entries: 10
Default

The code won't matter if the hardware isn't right. What is the external circuit?
__________________
First comes the hardware, then the software.
Reply With Quote
  #4  
Old 11-10-2008, 12:38 AM
donutchance donutchance is offline
New Member
 
Join Date: Nov 2008
Location: Singapore
Posts: 5
Default reply


Last edited by donutchance; 11-10-2008 at 12:44 AM. Reason: :) <-:
Reply With Quote
  #5  
Old 11-10-2008, 12:41 AM
donutchance donutchance is offline
New Member
 
Join Date: Nov 2008
Location: Singapore
Posts: 5
Default Reply

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
Reply With Quote
  #6  
Old 11-10-2008, 01:03 AM
beenthere's Avatar
beenthere beenthere is offline
Senior Member
 
Join Date: Apr 2004
Location: Missouri, USA (GMT -6)
Posts: 15,815
Blog Entries: 10
Default

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.
__________________
First comes the hardware, then the software.
Reply With Quote
  #7  
Old 11-10-2008, 07:39 AM
donutchance donutchance is offline
New Member
 
Join Date: Nov 2008
Location: Singapore
Posts: 5
Default ok forget about the thing.

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
Reply With Quote
Reply   Post New Thread

Tags
, , ,


Similar Threads
Thread Thread Starter Forum Replies Last Post
Atmel 8515 micro controller C programme help! Socheara Programmer's Corner 10 04-14-2008 01:49 PM
My transmitter doesn't work completely to my satisfaction. mik3ca Radio and Communications 12 04-12-2008 04:05 AM
help regarding atmel 89c51 micro controller shiva21h Programmer's Corner 5 04-10-2007 01:53 PM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:25 PM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin
Copyright ©2000 - 2014, vBulletin Solutions, Inc.