Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Please Help

Status
Not open for further replies.

Elbobbo

New Member
The project I am currently doing asks me the following:
write a program for a PIC16F84A that converts your a number (10 ASCII characters), one character at a time, to the excess-three code. Each converted character is to be displayed on 4 LEDs connected to Port B (B0 to B3) of the microcontroller. Further, each converted character will be ON for 4 second and OFF for 1 second. Once all characters have been displayed the program will continue to run with all the LEDs flashing (ON for 1 second and OFF for 1 second then repeat this infinitely).

So far I don't have much,

Firstly I am unsure how to call a particular digit from the number eg "0" from "0648321975"

I under stand that I'll subtract 48(decimal) from the number (ASCII "0"="48" decimal - 48 decimal), and then add (3) to get the excess three value (3) then Plug this into Port B(B0 to B3) followed by a delay of a second, then turn off/ initialise Port B again.
Using a counter to count the amount of numbers( if under 10 processed got to start again) ( if more than 10 got to the flashing sequence)

Any help will be greatly appreciated.
Cheers
 
1)First make a table of all the characters:- 0648321975
2)Set the port pin directions
3)Set a variable to count down from 10
4)Create a loop to look at each character in the table in turn
5)Within the loop, load the character and deduct 48 and simply put it on PORTB and delay
6)Create a forever loop to flash the LED's..
 
Are you doing it in assembly?

PIC84 went out with the ark. You must have a very erudite teacher.
 
Are you doing it in assembly?

PIC84 went out with the ark. You must have a very erudite teacher.
They still use the 6800 here in England... Can't get my head around that one..
 
Yeah first year elec engineering for a computer engineering subject.
I hardly understand what they are talking about in lectures. I have been reading pic microcontrollers by bates to get a good grip on it.
 
How is the ASCII number being presented to the MCU? I did something similar awhile back in which the ASCII characters were entered like this:
Code:
Freq                  
                addwf   PCL,f
                dt      "05000000",0

In that case, the ASCII string was included in the code, and I just stepped through the values and tested for zero to end the loop. It was presented here: https://www.electro-tech-online.com/articles/demo-assembly-code-ad9850-dds-signal-generator.755/

Obviously, it doesn't do the 3-excess coding and converts the ASCII to an actual value (slowly), but the initial part (see: user defined frequency in the link) may give you some help. The instruction sets for the 12F683 and 16F84A are the same. Banking may be a bit different.

Edit: Once you extract the individual ASCII, you can go directly to a table with an offset or convert the individual ASCII to hex or dec and go to to a non-offset table to get your Excess-3 code for display on your LED's.

John
 
Last edited:
How is the ASCII number being presented to the MCU? I did something similar awhile back in which the ASCII characters were entered like this:
Code:
Freq              
                addwf   PCL,f
                dt      "05000000",0

In that case, the ASCII string was included in the code, and I just stepped through the values with tested for zero to end the loop. It was presented here: https://www.electro-tech-online.com/articles/demo-assembly-code-ad9850-dds-signal-generator.755/

Obviously, it doesn't do the 3-excess coding and converts the ASCII to an actual value (slowly), but the initial part (see: user defined frequency in the link) may give you some help. The instruction sets for the 12F683 and 16F84A are the same. Banking may be a bit different.

John

Yes similar to yours as,

; Student number ASCII table ..............................

snum addwf PCL,F
dt "0061076281" ;Student number
 
You have to start by making a template for PIC16F84 in Notepad
 

Attachments

  • 3CODE.asm
    2.2 KB · Views: 269
This is my flowchart at the moment,
upload_2017-5-24_20-20-59.png


supposed to have YES coming off to the LED flashing and NO to continue down the flowchart
 
This is all wrong:


; Initialise Port B .................................

BCF status, RP0 ; bit clear
CLRF PORTB ; Initialize PORTB by
; clearing out data latches
BSF status, RP0 ; Select Blank 1
MOVLW 0x10 ; value used to initialise data direction

MOVWF TRISB ; Set RA,<3:0> as outputs
; RA4 as input
; TRISB <7:5> are always read as '0'
 
; Initialise Port B .................................

BCF STATUS, RP0 ;

CLRF PORTB ; Initialize PORTB by clearing output data latches

BSF STATUS, RP0 ; Select Bank 1

MOVLW F0 ; Value used to initialize data direction

MOVWF TRISB ; Set RB<3:0> as outputs
; RB<7:4> as inputs



Any better?
 
When you are in bank0, the operation clrf portB is actually operating on the tris register and making all pins output.
 
So i guess i can just use the operation clrf portB without the rest, since I actually don't need any inputs.
 
You have to make portB output and then you can make all outputs LOW, if you want to.

The first thing you have to do is create a 1 sec delay
 
ok, well i am stuffed. I dont have a clue what I am doing.o_O

I am trying to get the code to look up one of the ASCII characters at a time, using the combination of STRLEN and ASCLEN. But i just cant get my head around it.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top