0% found this document useful (0 votes)
7 views11 pages

Assignment Microproccessors Luis

Uploaded by

Luisendorf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

Assignment Microproccessors Luis

Uploaded by

Luisendorf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

Microproccessors System Luis de Leon Sastre

1. Assignment Aims:-

Write a program which will read an analogue voltage from the potentiometer,
convert it into an 8-bit binary number and produce a display on the LED’s such that the
higher the number, the more LED’s will be ON. In other words, the LED’s will take the
form of a Bargraph. The number of LED’s that are ON should take the form of the
following table.

Value Read in (Decimal) (Binary) Leds

0 0000 0000 All off


1--31 0000 0001 - 0001 1111 Led 0 on
32--63 0010 0000 - 0011 1111 Leds 0 to 1 on
64--95 0100 0000 - 0101 1111 Leds 0,1,2 on
96--127 0110 0000 - 0111 1111 Leds 0,1,2,3 on
128--159 1000 0000 - 1001 1111 Leds 0 to 4 on
160--191 1010 0000 - 1011 1111 Leds 0 to 5 on
192--223 1100 0000 - 1101 1111 Leds 0 to 6 on
224--255 1110 0000 - 1111 1111 All Leds on

2. System Analisis and Procedure:-

The system has to receive an analog signal of entry, this sign is from 0 to 5 volts.
The volts (0 to 5) are inside a range of decimal values from 0 to 255. These decimal
values must turn into a binary code of 8 bits with it between 0000 0000 and 1111 1111.
With this range of values, it depends on the values that interfere., turn on from the 1 to 8
of the LED's that we have.

To do this, we have to see the previous table and observe what happens with the
three bits with MSB, if we see these it is possible to observe that in the range of values
for every line of the picture, the three bits MSB (5, 6, 7) are the same in the range, for
example, in the second line of the range is 0000 0001-0001 1111 and in the third line is
0010 0000-0011 1111. When the process has been observed we could continue. We can
see that one bit is incremented from 0001 to 0010 and from 0001 to 0011.

The second step consists of multiplying every range of values with a mask with the
value 1110 - 0000, with this mask only there will be the three bits with the MSB, later
we will have to do a swap between the bits LSB and MSB and will be able to obtain
0000 - xxx0 where x are the bits that it had before the MSB. The following step is to
turn to the right the bits a bit to have the three bits of major weight in the first three
positions (0,1,2).
It is say the bits of major weight they have passed to be those of minor weight, and
inversely.

S07001907 1
Microproccessors System Luis de Leon Sastre

Now, to end, the value in binary, they must be checked and depending on it, the LED's
turn into modals to described into the table..
3. The Flow Chart:-

START

INITIALISATION
PORT A/D

START A/D
CONVERSION

READ
RESULT

IS THE
RESULT
ZERO=?

NO
HASK OUT 5 LSB’s OF
THE A/D VALUE

SWAP NIBLES 4 MSB YES


WITH 4LSB

TURN RIGHT BY
1 BIT

TAKE DISPLAY
PATTEN FROM
LOOK-UP TABLE

DISPLAY ON LED’S

ALLOW A/D
ADQUISITION TIME
START A/D
CONVERSION

S07001907 2
Microproccessors System Luis de Leon Sastre

:- 4. Program code assembler:-

LIST p=16F874, R=DEC


__FUSES _XT_OSC & _WDT_OFF & _CP_OFF & _PWRTE_ON
include "P16F874.inc"

RESULT EQU 0x20 ;START THE RAM


org 0x00 ;RESET THE VECTOR
call Initial1 ;SETUP HW
call Initial2 ;SETUP A/D (analogic/digital)
goto START

TABLE addwf PCL,1 ;ADD PCL+1 FOR RETURN THE NUMBERS OF LED
retlw b’00000000’ ;ALL LEDs OFF
retlw b’00000001’ ;LED 0 ARE ON
retlw b’00000011’ ;LED 0,1 ARE ON
retlw b’00000111’ ;LED 0,1,2 ARE ON
retlw b’00001111’ ;LED 0,1,2,3 ARE ON
retlw b’00011111’ ;LED 0,1,2,3,4 ARE ON
retlw b’00111111’ ;LED 0,1,2,3,4,5 ARE ON
retlw b’01111111’ ;LED 0,1,2,3,4,5,6 ARE ON
retlw b’11111111’ ;LED 0,1,2,3,4,5,6,7 ARE ON

initial1 bsf STATUS,RP0 ;GO TO BANK1


clrf TRISB ;PORTB IS PUT LIKE OUTPUT,PORTA IS INPUT
bcf STATUS, RP0 ;BACK TO BANK0
return

initial2 movlw 0xC1 ;ADCON0 & ADCON1 ARE INITIALIZED


movwf ADCON0 ;PUT IN ADCON0 0xC1
clrf AnDigCON1 ;PORTB IS CLEANED
return

START bsf ADCON0,2 ;THE CONVERSION OF THE VALUE START


LOOP btfsc ADCON0,2 ;THE COVERSION OF THE VALUE HAS FINISHED
goto LOOP
movf ADRESH,w
movwf RESULT ;MOVE RESULT TO THE WORKING REGISTER
movf RESULT,1 ;MOVE RESULT TO THE FILE REGISTER
btfss STATUS,Z ;CHECK IF RESULT IS =ZERO
goto MSB ;IF RESULT IS NOT=ZERO, GO TO MSB
clrf PORTB ;IF RESULT IS=ZERO, TURN OFF ALL LED’s
goto START ;START A NEW CONVERSION

MSB movlw 0xE0


andwf RESULT,1 ; 0xE0, THE RESULT FOR HAVE ONLY 3 MSB
swapf RESULT,1 ;SWAP RESULT FOR HAVE 3 MSB IN THE RIGHT
rrf RESULT,w ;ROTATE 1 BIT TO RIGHT FOR HAVE 00000xxx
call TABLE ;HAVE TO SEE NUMBER OF LED’S SHOULD BE ON
movwf PORTB ;TURN ON THE LED’s
goto START ;START A NEW CONVERSION
end

S07001907 3
Microproccessors System Luis de Leon Sastre

5. Test Data (with MP-LAB):-

When in the program there is no errors, it has to be simulated to demonstrate that


there have been fulfilled all the things for that the program has asked. For it they have to
show on the screen the window with all the records that have been in use for doing the
program. In these records there appeared the different changes realized during the
execution..

Picture 1.

This screen show that the program hasn’t any errors because the line of build is
green. Build Successful.

S07001907 4
Microproccessors System Luis de Leon Sastre

Picture 2

This screen show the window with all registers when these still have 0 values.

S07001907 5
Microproccessors System Luis de Leon Sastre

Picture 3

This screen shows that the program does the conversion, and finishes when the
bit 2 of registerADCON0 changes to 0. If the program is not in the trainer PIC, this bit
must be changed by a manual form and it put to 0. When the conversion has ended, the
process continues verifying if the number is 0 or not. And so on.

S07001907 6
Microproccessors System Luis de Leon Sastre

Picture 4

This screen shows when the record WREG has '11100000' in the binary one, to do
the AND with the result of the conversion, to have only 3 MSB (bit7, bit6, bit5). Then
the change has to be done to have this bit in the positions bit3, bit2 and bit1 of the
record of RESULT, to finish, the record of RESULT has to turn a bit to the right.

S07001907 7
Microproccessors System Luis de Leon Sastre

Picture 5

This is the final screen, this shows that in the PORTB there is a number in
binary with the exact number of the led's that must be connected, in this case in which
the number, the first three bits were 5, the number of the led's that must be connected is
six (the led's 0 to 5).

6. Testing (practise in lab):

S07001907 8
Microproccessors System Luis de Leon Sastre

When the simulation has ended and the works of the program have executed
and realized correctly the following step it is the load the program in the PIC and to
check that the system works according to the specific asked information.
In the following pictures we can observe that the system works well.

Picture 6

7.-Applications and finality:

The uses that can be designated to the created system, can be used by certain
fields inside which they can be the mechanical, car industry and even in domestic
domiciles.

S07001907 9
Microproccessors System Luis de Leon Sastre

The best use that can give him is to realize alarms and visual alerts indicating
that a certain limit has excelled itself of some system, for example we it can use in
industries when there is exceeded a limit of load, which is illuminated determined leds,
depending on the overcharge. Or also could to use in braking systems in car, depending
on the intensity of brake, more or less leds ignitions.
Another possible purpose is for the systems that use certain conditions or states of limit,
every led, It could be a different colour, and to determine the limit.

In the great industries this system can be applied for the level of noise, for
example using a sensor, this sensor gives a variable analogical signal according to the
noise level.

8. Conclusion:

At first it is a bit complicated because you have to be familiar with the program
assembler, as are the main programming commands, the following is to see and study
the characteristics of the PIC to be programmed, and get an idea of what actually takes
to do. Studying the functionality of the program and the possible methods that would
enable its proper functioning. I had to consult parts of code and design to understand the
codes and consult websites and questions in forums. It is a code that the first time it is
difficult to understand because it is quite problematic, but after making small practices
and see the functioning of the code can understand the role of the instructions.

We start with simple and basic instructions, which are easy to understand, and little
by little more complicated structure of the programme. Using small pieces of code, it is
possible to assimilate the knowledge needed for programming in assembler.

The study and implementation of programming has proved most beneficial to develop
my level as a programmer within the functions of assembly. It is a program to reach an
expert level requires many hours of studying and understanding the instructions of the
code, but that gradually we can go to learn.

9.-Reference and Bibliography:

http://www.microchip.com

S07001907 10
Microproccessors System Luis de Leon Sastre

http://micropic.galeon.com/index.html

http://www-pagines.fib.upc.es/~sdmi/pdfs/ManualPicLab.pdf

http://platea.pntic.mec.es/~lmarti2/PRAC4.pdf

http://www.iesleonardo.info/ele/tra/VARIOS/t-manual_PIC/

http://www.uah.es

S07001907 11

You might also like