serial data application using PIC16F84A to light up leds

Status
Not open for further replies.

pulpak

New Member
hi...
i'm desperately seeking for help...i'm trying to complete this application but i cannot seem to light up the leds...i dunno whether
my program is functioning correctly..pls....i desperately need help...the details of my application are given below....plss could you correct the program as it doesnt seem to function ....

Attachments

• 1.7 KB Views: 335

TheAnimus

New Member
Hi, i've quickly clanced over your source code and protocol, and one thing leaped out infront of me, you have set the interupt vector, but you haven't set the program start vector, remeber u can't realy on the space between 000-004 been NOP, as such i would recomend putting the lines
Code:
ORG   0x00
GOTO   start
also its probably worth while using the include file for the 16F84A rather than define all the names yourself, if your in MPLAB try this
Code:
LIST 	P=16F84A
INCLUDE	"p16F84a.inc"
at the top of your file.

If its not somthing that mundain i would take a look at your code, the timing methods are no were near acurate, and also from my scan read of ur code it seams that it would only update PORTB if all the LEDs where to be set high. Also it dosen't seam to let the loop adjust for the time changes depending on the on or off:
0.6ms|0.3ms| 1ms |0.6ms|0.3ms| 1ms |0.6ms|0.3ms| 1ms |0.6ms
0.6ms|0.3ms|0.6| 0.3|0.6|0.3 |0.6|0.3 |0.6 | 0.3 | 1ms |0.6 | 0.3 |
from the internet.txt file you attached.
enless the 0.3 is a typo, and 0.4 is ment, then the time between Mark and Space is 0.1ms shorter (this often happens in strange protocols) but your code dosen't allow for this.

Personally i would use the TMR0 register, and test the value of it between detected Highs. This way a high between the the pulse (the 'mark' if you will) can be determined by checking the value of TMR0.

pulpak

New Member
programing the tmro reg

hi there thanx for ur reply.....u've been great help...
but could u plss tell me how i can program the tmro register to detect the highs and lo's...i'am not familiar with the tmro register function..still a newbie here.. ......

if possible could u give me a sample code to work on.......plsssssssssss....

thanx 4 ur help man....greatly appreciate it...ur my saviour....

TheAnimus

New Member
Hey, no problem, i think that the "TIMER" registers are all too often overlooked, and only ever used for a regular interval.
Basically TMR0 (its a zero, not an o) is a 8 bit counter, it can be set to automatically increment in the OPTION_REG, the pre-scaler is also controlled here. Basically the pre-scaler controls how many internal clock cycles have to happen before TMR0 is incremented. Remeber by that i mean an instruction cycle, ie resinator / 4.

To enable the increment from instruction cycle, BCF OPTION_REG, T0CS; (timer zero, clock source)

The pre-scaler is enabled on TMR0 with PSA (1 = on, 0 = on the watchdog timer)
The pre-scaler is controlled with PS0 , PS1 , PS2.

to enable the pre-scaler with a 1:8 ratio the code would look like
Code:
BCF  OPTION_REG, T0CS
BSF  OPTION_REG, PSA
BCF  OPTION_REG, PS0
BSF  OPTION_REG, PS1
BCF  OPTION_REG, PS2
What we use this for is to determine how long it has been between high pulses

Code:
    __          __
|  |        |  |
___|  |________|  |____

__    __    __
|  |  |  |  |  |
___|  |__|  |__|  |____
So, we have some code that waits for the rising edge, then magnitude test the value of the TMR0 register, we need to make sure the TMR0 register won't overflow, carefull use of the pre-scaler is important here

Code:
rxreloop:
MOVLW  0x08
MOVWF  LOOPREG
rxloop:
CLRF    TMR0
BTFSS    PORTA, 0 ; first "mark"
GOTO  $-1 ; First mark has passed, now wait for what is either going to be a signal high, or the next mark BTFSS PORTA, 0 GOTO$-1
MOVLW  0x10 ; this constant must be worked out, so the time between marks (stored in tmr0)
; plus this constant is going to overflow, but a signal high, won't.
BTFSC   STATUS, C
GOTO  BitHigh
RFL     RXREG, F
BCF     RXREG, 0
DECFSZ   LOOPREG, F
GOTO rxloop
AllRecived:
; Your code ere! the byte has been recived, do with it what u wish, the world is urs, knowledge is power etc.
GOTO   rxreloop
BitHigh:
RFL     RXREG, F
BSF     RXREG, 0
DECFSZ   LOOPREG, F
GOTO rxloop
GOTO  AllRecived
I hope this code is correct, i haven't tested it just tapped it up here in reply.

out of intrest what is this for? it seams a rather strange project!

pulpak

New Member
sir..help me..plsss

Thanks sir for ur help...i greatly appreciate ur time and concern...i have a few questions that i'd like to ask ..
i'm currently trying out ur code (thanks again, at least i have some ideas to work on) i bumped into some dead ends.

1)in the rxloop u stated a GOTO $-1 instruct.....does this mean goto start of program?? 2)the rxreg and loopreg can i define it to be anywhere in the general purpose bank of the PIC 3) how do i know when/where i can set an output to the pins on portB(this is where the LEDS are going to be) based on the code u've given. say for the first input after the first mark is detected, a low is detected i want to set a bit in sw1(storage register) whereby the contents of this reg. is moved to portB and it will set the corresponding pin (RB0-RB7) thus an led connected to that pin will light up. in ur code, after the first mark is detected it will search fro a high...after a high of 1ms it will....i dont quite get this part of the code...the bithigh part..can u further elaborate... 4) at the all receive part this is where i should place my code....but how can i manipulate the information i got the part u've given me...i'mmm lossssssssssssttt.. plsss...i know some of my questions might seem awkward...but can u plss help me..u've been very kind..i can only offer my thanx and appreciation..... :lol: TheAnimus New Member hey sorry about the delay in my reply. okay first question$ is like address of current instrcution, the when building the ASM this is converted to the current memory posistion (think like line numbers in basic)
because its GOTO \$-1 it will send execution to the line above. ie the bit test. this is how an "edge" is dedicated in most code i write!

2nd questions, absolutely correct, as long as they are in the current "bank" that will be selected when executing (must be 0 for the pin reading!)

right the 3rd and 4th question require the same awnser.
how i detecting if the bit is a high or a low, is by timing how far appard the marks are if u look at the ASCII art graph i did, it shows that a Low and a High waveform

this code essentially works out how long has ellapsed between 2 highs, it does this because TMR0 will of been incrementing (from the pre-scaller)

MOVLW 0x10 ; this constant must be worked out, so the time between marks (stored in tmr0)
; plus this constant is going to overflow, but a signal high, won't.

is the code that does that we relay on the idea off adding a number to TMR0 to make it overflow, ie if the "marks" where always 230ms appart, and TMR0 was on a 1MS increment, u would need to add about 30decimal to make it overflow when there has been no high in between the time that 2 marks should occour in, i don't know if anyone else can explain that any better! hopefully someone will try!!!

as to know when u can update PORTB currently it is testing to see if 8 bits have been recived then all recived is called
u can just MOVF RXREG, W MOVWF PORTB there

Good Luck!

Status
Not open for further replies.