Tuesday, August 31, 2010

Riker Island Visiting Rules



NOTE: The programs in this tutorial are on the following link.

http://www.mediafire.com/?ydb5y3b6e3ljutg


While I will not give complex examples and I will use 100% of the micro, I will address this issue in function to a microcontroller (MCU) PIC family from Microchip

company. Microcontroller study the PIC16F84A PIC16F84A as it is the most common more accessible and easier to set record after its simplistic and configurations. Of course there are with more or fewer pins, with more or less preestaciones and different prices, but to start is the most estable.Descripción
PIC16F84A microcontroller (not go into details very deep for the mere echo of the guide serves all the public.)
a. 35 instructions. B.
External clock can be in the RC (RC-circuit) or XT with a glass of up to 4MHz (in default mode). C.
Flash memory of 1024 14-bit address word (here anger the program.) D.
64bytes Ram memory (data will be used to host variables values \u200b\u200bin the program). E.
64bytes EEPROM (to accommodate data we want to go away after rebooting the MCU). F.
8bit ALU (ALU is the arithmetic and logic unit, which is responsible for numerical operations). G.
Interruptions by INT/RB0 pin on the TMR0 timer, EEPROM for OVERFLOW and the state change on pins RB4 to RB7.
h. 1000000 to read and write cycles for EEPROM, and data retention for 40 years. I.
13-pin input and output to the outside. J.
Two ports E / S PORTA and PORTB bit 8bit 5. K.
A counter / timer TMR0 8bit call.
l. Electrical Characteristics: Temp -55 ° C to +125 ° C. 5V supply voltage. Maximum current
PORTA 50mA. 100mA maximum current of PORTB.

Principles assembly
In this guide we will learn what the assembler or Assembler language, in order to understand the logic that owns and eventually develop some simple programs.
Each microcontroller has its different instruction set, the difference is in the manufacturer, I mean the set of instructions of a microcontroller of the mark Freescale (Motorola) "MC" is not equal to that of AVR (Atmel) "AT" or the Microchip "PIC" microcontrollers that we will see in this guide are of the firm Microchip and chose this particular because it has more kid instruction set of all (only 35 instructions for the line of 8bit). Then show you a picture with the instructions of the PIC.

Once we consider the instructions the pic driving, we must bear in mind that all of those pin that has thus are bidirectional input / output, and supporting clock rates and other settings should configured so that the microcontroller can know what we want to do and how we do it.
First on the agenda we have to tell the compiler that we want to use micro and the library where it will take instructions from the pic, this will write the first two lines program, leaving a space tab:

LIST P = 16F84A INCLUDE

To do this in the header of the program will write a series of characters indicating the type of watch that we will use if we are to use the watchdog (we know when the program crashes), protection code, and for example the delay that are behind the power so as not to generate a voltage spike that causes erratic shots.
that line would be:

__CONFIG _CP_OFF \u200b\u200b& _WDT_OFF & _PWRTE_ON & _XT_OSC


will then variables used with the EQU instruction means Equal or more, here was the hex address 30 and 31 only because I thought that but to refer to a memory point. is only for defining variables. there are other ways but they are more Abansa.


PEPA PEPE EQU EQU 0x30 0x31


After that we started the program, we must tell the micro to get started there, for it we're going to put the instruction:

ORG 0


This instruction tells us that the orgy of the program (ORG) is in the zero position memory (0) also can be placed in hexadecimal would 0x00, or other bases but the most common are those dos.Seguido of this instruction must configure the ports of the microphone.

bsf STATUS, RP0 clrf TRISB


clrf TRISA bcf STATUS, RP0


Here are three new instructions, the names of the two ports and the status that you will configure the microphone. Serious
instruction (BSF) means BitSetF this means that will setear (set to 1) bit of F (F is the value of the variable, in this case the variable is RP0, which is housed in a set variable called STATUS) RP0 will therefore be 1. STATUS has 8 bits where the RP0 bit is equivalent to number 5 graphically serious bone STATUS = 00001000.
then displays the instruction (CLRF) f this is clear, I mean delete the contents of f, but technically it reset. in this case will set TRISB (all its contents) to zero, as is the registration TRISB PORTB pin bone the integrated 8 port b, that if they are to 1 are inputs and 0 are outputs. in this case to say that deleting all the 8 bit TRISB to zero, bone
TRISB = 00000000, thus will all outputs. if she wanted would have to be input qeu be 11111111 or 11001100 can be mixed bone for example. CLRF instruction but no longer serve us because that just reset all variable. Ahohra
repeats the same but with TRIS PORTA bone registration that also puts zeros, hence also are outputs. Echo
Once this configuration appears STATUS, RP0 but with the instruction (BCF) which is BitClearF, bone (set to 0), now RP0 = 0 and STATUS = 00000000. with this we say we left the config, bone fijencen who first entered the settings, then configure and then left the configuration.
Now we started the program itself, which in our case will turn on LEDs to output port B, for this we will write:

modded
MOVLW b'01010101 'MOVWF PORTB GOTO
modded


Note that there are three directions, MOVLW, MOVWF and is moving GOTO.MOVLW the literal to W (where W is the RAM), W MOVWF is to move (so which moved earlier) F it was like we had said before the bit of the record in this case we refermios to PORTB and GOTO to last is "go."
then read this, first get a modded in the first line, this is a label that can have any name, refers to a point in the program. then a space appears MOVLW tabulation and then another tabulation of space appears b'01010101 'move this line says W the literal, the literal is b'01010101' which means the letter b to speak in binary (could be h hex, d for decimal, or octal, etc. ..) but because we Vinaria is more visible LED to be lit is the one with the 1 and it will be off is the one with 0, then will move to W 01010101 (which was the ram).
in the next row with a space and a tabulation tabulation MOVWF appears more and appears PORTB, here you are moving the contents of W to PORTB, remember that before he moved to W 01010101, so will move it to PORTB PORTB now is 01010101, as referred PORTB pic port (physical port "paws") the LEDs will be there on or stay apagadaos according to the binary number. Finally
tabulation shown by the GOTO and another tabulation the Modder, this means that going to jump modded label that was set up, which means that the program enters bone LOOP cyclically makes this all the time.
to terminate the program now need to tell, and it ends ponermos instruction:

END

Here temrino all, what remains is to compile this program with the Microchip MPASM (it's free and download page) and this will generate a series of files which are files of records, logs, comments, and we are interested in the *. HEX which is the code to be read in the pic, well this last file it will create if the program has no errors, but does not believe and should be corrected the codigo.Una Once we have this file just have to save the pic and for that we can use any program with any interface such as ICPROG (free) and the JDM programmer for serial port. only remains to record the pic and ready to connect the LEDs, glass and feed it 5V.

program:

;*************** endend PROGRAM LED BY THE PORT B \u200b\u200b**************** ****** ; ** Powered by modded , spaces between instructions and literals are made with tabs, not spaces. and the comments can go after a point and coma. LIST P = 16F84A INCLUDE __CONFIG _CP_OFF \u200b\u200b& _WDT_OFF & _PWRTE_ON & _XT_OSC PEPE EQU 0x30; Declaration of variable PEPE PEPA EQU 0x31; Statement of PEPA variable ORG 0; Source program in the zero position

bsf STATUS, RP0; The entrance to the configuration ports, putting a bit RP0 of STATUS clrf TRISB; It resets the TRISB register, this, way
transformed into outputs clrf TRISA; It resets the TRISA register of this, as they become
outputs bcf STATUS, RP0; Exit the configuration of ports by resetting the bit RP0 of STATUS modded, Label modded
MOVLW b'01010101 '; Moves 01010101 to
W MOVWF PORTB; Move the contents of W (01010101) to PORTB
modded GOTO, (Display is in the output)
; Jump to the label modded END; End

program
The circuit would be:


Now using the same circuit we get on and off at a speed visible.

;*************** Endend PROGRAM LED BY THE PORT B \u200b\u200bFLASHING **********************
; ** Powered by modded ; To attain that are flashing you must create a delay, we know that the micro is running to
; 4MHz (every instruction consumes 4 cycles hence the actual speed is 1MHz) then we would have to
down, speed it to see an LED turn on and off at 1MHz is ungodly, then to be vicible eg every 0.5 s
, we do a delay, I mean we do wasting time micro, as we accomplish this by making the micro pass, for a certain number of times instruction and then continue with the program, the number of times you go through that
; instruction determines the time to lose, hence the delay.

LIST P = 16F84A
INCLUDE

__CONFIG _CP_OFF \u200b\u200b& _WDT_OFF & _PWRTE_ON & _XT_OSC

PEPE EQU 0x30; Declaration of variable PEPA PEPE
EQU 0x31; Statement of PEPA variable
ORG 0 ; Source program in the zero position

bsf STATUS, RP0; The entrance to the port setting configuration one bit RP0 clrf TRISB
STATUS; It resets the TRISB register, so they become
outputs clrf TRISA; It resets the TRISA register, so they become

outputs bcf STATUS, RP0; Exit the configuration of ports by resetting the bit RP0 of STATUS

modded, Label modded
MOVLW b'01010101 '; Move 01010101 to
W MOVWF PORTB; Move content of W (01010101) to PORTB (Display is the
output)
MOVLW b'10101010 '; Move 10101010 to
W MOVWF PORTB; Move the contents of W (10101010) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous GOTO
modded, modded Jump to the tag DELAY, DELAY Label
MOVLW 150; We move the decimal number 150 to W movwf
PEPE; Move the contents of the variable W
PEPE PEPE decfsz ONE, ONE Label , Decrement PEPE
GOTO ONE, ONE goes to the label going to do this loop until zero is
PEPE RETURN; Once PEPE is zero, skip the GOTO instruction and will ONE, RETURN, with RETURN instruction, which was called earlier returns
; bone returns to the CALL DELAY and continues with the program instruction bone, following which is GOTO modded.

END; End of program

In this program there are three more instructions, the CALL, RETURN and decfsz, the CALL as says the word called, in this case a label with the same name, once running the call to that label, you run the sub routine that has the label (in our If the sub routine DELAY) after the subroutine ends RETURN instruction appears that does nothing but return to the point where it was called the subroutine returns to bone main program just after the CALL instruction, in our case GOTO modded. The instruction means
decfsz Skip Decrement F Z, where F is the variable to decrease bone PEPE, and Z in the pic is a bone Flag this flag to 1 or 0 Warning something, in this case tells us when F is equal to 0, bone and this instruction is decremented, it is understood that going to a decreasing of the number that has PEPE, I mean when you go through there will be 150, when another pass through there will be 149, and thus to zero, and when is zero, the Z bit will have a 1 and there is bone Skip produce the "jump" instruction. Summarizing
PEPE will decrease until it is zero and zero when an instruction is going to jump, because while not zero will go to the instruction that sige GOTO ONE and when zero will skip that instruction and will go RETURN directly. Some instructions
clock consume a shekel and two, such as CALL, GOTO, RETURN consume two cycles.
normal every instruction consumes those who use spit 1us 2us, therefore if we 150 times there are going to have
2 of CALL will happen 1 time -----------------> 2
1 of MOVLW will happen 1 time ------------- ----> 1, MOVWF 1
will happen 1 time -----------------> 1
1 of decfsz will happen 150 times ------- 2 150 255
----> GOTO will happen 1 time ----------------->
2, 300 510 RETURN will happen 1 time ----- 2
------------> 158us, bone that it will take 456 microseconds 0.000456 s something that we will not notice ... so here Deveria take more if we put 255 (which is 11111111 thus the maximum number as it is an 8-bit micro) will be 771us delay 0.000771 bone, well here we will not notice., then we have other than using a decfsz more, but we will use a in the other, I mean the first decfsz going to count the times that will happen the second decfsz which in turn will have a number., would be:

DELAY; Label
DELAY MOVLW 150; We move the decimal number 150 to W movwf
PEPE; Move the contents of the variable W PEPE
MOVLW 150; We move the decimal number 150 W MOVWF PEPA; Move the contents of the variable W ONE decfsz
PEPA PEPE; Label ONE GOTO ONE Decrement
PEPE, goes to DOS label is going to do this loop until zero is
PEPE decfsz PEPA DOS, DOS Tag, Decrement PEPA until it is zero
GOTO ONE; goes to the label LOOP ONE to repeat the RETURN; returns to the program


Bone will decrease the UNO LOOP until it becomes zero after zero decrmentea is only 1 in DOS and re-LOOP decrease the UNO LOOP 150, there decremented LOOP another one of the DOS and the 150 back dec LOOP ONE then you could say that would be 150 per 150.
Then the calculation of time here seriously.
2 of CALL will happen 1 time -----------------> 2
1 of MOVLW will happen 1 time -----------------> 1, MOVWF 1
will happen 1 time ------------ -----> 1
1 of MOVLW will happen 1 time -----------------> 1, MOVWF 1
will happen 1 time ------ -----------> 1 1 of decfsz
will happen 150 times -----------> 150 2 GOTO will happen 1 time -----------------> 300
1 of decfsz will happen 150 times -----------> 150 255
2 of GOTO will happen 1 time -----------------> 300 510
2 of RETURN will happen 1 time ------------- ----> 2
But the difference is that within a LOOP LOOP another so multiplication would be a 450 * 450 + 8 = 0.202 s 202ms bone but may take longer to make it look easier. and make PEPA PEPE 255 and 255 would give us 585ms 0.58s bone there is visible speed therefore we would stay a program as follows.

;*************** endend PROGRAM LED BY FLASHING PUERTO B ********************* * ; ** Powered by modded
; To attain that are flashing you must create a delay, we know that the micro is running to
; 4MHz (each instruction consumes 4 cycles hence the actual speed is 1MHz) then we'd come down ; speed because you see an LED turn on and off at 1MHz is ungodly, then to be vicible eg every 0.5 s
, we do a delay, I mean we do lose time to the bus, as we accomplish this by making the micro
pass, for a certain number of times instruction and then continue with the program, number of times you go through that ; instruction determines the time to lose, hence the delay.

LIST P = 16F84A
INCLUDE

__CONFIG _CP_OFF \u200b\u200b& _WDT_OFF & _PWRTE_ON & _XT_OSC

PEPE EQU 0x30; Declaration of variable PEPA PEPE
EQU 0x31; Statement of PEPA variable

ORG 0; Source program in the zero position
bsf STATUS, RP0; The entrance to the port configuration putting a bit RP0 of STATUS
clrf TRISB; resets the registry TRISB, thus become
outputs clrf TRISA; It resets the TRISA register, so they become
outputs bcf STATUS, RP0; Exit the configuration of ports by resetting the bit RP0 of STATUS

modded, Label modded
MOVLW b'01010101 '; Moves to W 01010101 MOVWF PORTB; Move the contents of W (01010101) to PORTB (Display is in the output)
CALL DELAY; Call DELAY and once you finish your routine DELAY continuous back and
MOVLW b'10101010 '; Move 10101010 to
W MOVWF PORTB; Move the contents of W (10101010) to PORTB (
is Display at the exit)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
modded GOTO, jumps to label
modded
DELAY, DELAY of 0.58 seconds Label
MOVLW 255; We move the decimal number 150 to W movwf
PEPE; Move the contents of the variable W PEPE
MOVLW 255; We move the decimal number 150 to W movwf
PEPA; Move the contents of the variable W
PEPA PEPE decfsz ONE, ONE Tag, Decrement PEPE
GOTO ONE; goes to the label DOS is going to do this loop until zero is PEPE decfsz PEPA DOS, DOS Tag, Decrement PEPA until it is zero
GOTO ONE; goes to the label LOOP ONE to repeat
RETURN, RETURN, with RETURN instruction, returns where previously called
; bone returns to the CALL DELAY and continues with the program instruction bone; following is GOTO modded. END; End of program


In the same way we can do more sequences as you can imagine this we have two sequences progam

MOVLW b'01010101 '; Move 01010101 to
W MOVWF PORTB; Move the contents of W (01010101) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
MOVLW b'10101010 '; Move 10101010 to
W MOVWF PORTB; Move the contents of W (10101010) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
modded GOTO, jumps to label modded
But Pdro be more
MOVLW b'00000011 ' ; Move
00,000,011th W MOVWF PORTB; Move the contents of W (00000011) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
MOVLW b'00001100 '; Move 00001100 to
W MOVWF PORTB; Move the contents of W (00001100) to PORTB (Display is in the output) CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
MOVLW b'00110000 '; Move 00110000 to
W MOVWF PORTB; Move the contents of W (00.11 million) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
MOVLW b'11000000 '; Move 11000000 to
W MOVWF PORTB; Move the contents of W (11 million) to PORTB (Display is in the output) CALL DELAY; Call to LATE LATE and once again finished his routine and continuous
modded GOTO, jumps to label
modded

by the code is there, we realize that the sequence to be seen in the LEDs is that are to be moved in pairs from right to left and luge again. Saldías
The code would

0-00000011
1 -
00001100 2 to 00110000
3-11000000


Well I leave the idea, for example to make a POV "persist of Vision" bone that is put fanes in and write when you turn, you can do with this program (of course not the most optimal way to do so as more instructions are dedicated to have less code but it is still valid and thus easy understand.) Example
to put a letter "A" will have to do it with ones and zeros., But on its side and The LEDs are on your side

PORTB outputs CHARACTER "A" EASIER TO LOOK


0 00 000 01 110 111
1 2 3 10 001 1 January 10 001 January 1

4 11 111 11 111 5 10 001 1 January

6 7 10 001 1 January 10 001 January 1


in our bar program would

MOVLW b'11111110 ' ; Move 11111110 to
W MOVWF PORTB; Move the contents of W (11111110) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
MOVLW b'00010001 ' ; Move 00010001 to
W MOVWF PORTB; Move the contents of W (00010001) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
MOVLW b'00010001 '; Move 00010001 to
W MOVWF PORTB; Move the contents of W (00010001) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous MOVLW b'00010001 ' ; Move 00010001 to
W MOVWF PORTB; Move the contents of W (00010001) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
MOVLW b'11111110 ' ; Move 11111110 to
W MOVWF PORTB; Move the contents of W (11111110) to PORTB (Display is in the output)
CALL DELAY; Call DELAY DELAY and once again finished his routine and continuous
modded GOTO, Salta
modded label

only thing to consider is that the speed must be faster than 0.58s therefore there has to play with the values \u200b\u200band PEPA PEPE and ready our POV with the letter A, if they can pnoer spaces if they're going to put more than one letter are not stuck, spaces are leds off so here would move b'00000000 'or make a PORTB CLRF that would go between lyrics.

;***** POV *************** **********
; ** Powered by modded
; Program for a POV with the word HI.

LIST P = 16F84A
INCLUDE

__CONFIG _CP_OFF \u200b\u200b& _WDT_OFF & _PWRTE_ON & _XT_OSC

PEPE EQU 0x30; Declaration of variable PEPA PEPE
EQU 0x31; Statement of PEPA
variable;
ORG 0; Source program at the zero position ;
bsf STATUS, RP0; The entrance to the port configuration putting a bit RP0 of STATUS
clrf TRISB; It resets the TRISB register, so they become
outputs clrf TRISA; It resets the TRISA register, so they become
outputs bcf STATUS, RP0; Exit the configuration of ports by resetting the bit RP0 of STATUS
;

modded MOVLW b'11111111 '; LETTER H
MOVWF PORTB; 11111111 CALL DEMORA ; 1
MOVLW b'00010000' ; 1
MOVWF PORTB ; 1
CALL DEMORA ; 11111111
MOVLW b'00010000' ;
MOVWF PORTB ; 1 1
CALL DEMORA ; 1 1
MOVLW b'00010000' ; 1 1
MOVWF PORTB , January 1 CALL DELAY
, 1 1 1 1 1
MOVLW b'11111111 '; January 1
MOVWF PORTB; January 1
CALL DELAY; January 1 CLRF PORTB; -------------------- SPACE ------ -------------------------------------------
CLRF PORTB; -------------------------- ------------------- SPACE
------------------------ CALL DELAY;
MOVLW b'01111110 '; LETTER OR MOVWF PORTB; 111111
CALL DELAY; January 1
MOVLW b'10000001 '; January 1
MOVWF PORTB ; 1 1
CALL DEMORA ; 111111
MOVLW b'10000001' ;
MOVWF PORTB ; 1 1 1
CALL DEMORA ; 1 1
MOVLW b'10000001' ; 1 1
MOVWF PORTB ; 1 1
CALL DEMORA ; 1 1
MOVLW b'01111110' ; 1 1
MOVWF PORTB ; 1 1 CALL DELAY; 1 1 1
CLRF PORTB; --------- SPACE ----------------- --------------------------------
----------- CLRF PORTB; -------------------------- -------- SPACE
----------------------------------- CALL DELAY;
MOVLW b'11111111 '; LETTER L
MOVWF PORTB; 11111111
CALL DELAY; 1
MOVLW b'10000000 ' ; 1
MOVWF PORTB ; 1 1
CALL DEMORA ; 1
MOVLW b'10000000' ; 1 MOVWF PORTB ; 1
CALL DEMORA ; 1
MOVLW b'10000000 '; 1
MOVWF PORTB, 1 CALL DELAY
; 1 1 1 1
CLRF PORTB; ------------------------ - AREA -------------------------------------------
CLRF PORTB; -------------------------- ----------------------- AREA --------------------
CALL DELAY;
MOVLW b'11111110 '; POINT
MOVWF PORTB; 1111111
CALL DELAY; January 1 MOVLW b'00010001' ; 1 1
MOVWF PORTB ; 1 1
CALL DEMORA ; 1111111
MOVLW b'00010001' ;
MOVWF PORTB ;
CALL DEMORA ; 1 1 1
MOVLW b'00010001' ; 1 1
MOVWF PORTB , January 1 CALL DELAY
, 1 1 1 1 1
MOVLW b'11111110 '; January 1
MOVWF PORTB; January 1
CALL DELAY; January 1
CLRF PORTB; ------------- SPACE -------------
------------------------------ -------------
CLRF PORTB; -------------------------- ------ SPACE
------------------------------------- CALL DELAY;
GOTO modded, modded label again
;

DELAY MOVLW .10 MOVWF PEPA
ONE
MOVWF MOVLW .60 PEPE PEPE
DOS decfsz

decfsz PEPA DOS GOTO GOTO ONE

RETURN;
END; End of program


This code must be done in the windows notepad or any other text editor pl year, where we setear new courier to respect the space characters and the tabulacions, and we will encode not forget that each space between the code is done with the key on ESPACE TAB instead, and the comments are after "."
Once everything is stored encrypted as *. asm (it belongs to the extension in assembler).

Now we proceed to go to the MPASM compiler


Then after the execution of that program window will appear to us to find the program POV.asm ('s settings by default and are thus not need to change anything.)


After that we will press Assemble button and show us compile a window with a progress bar, if the code is well done should be seen as follows.

Then we will create 4 files in the same place where the program, which will POV.COD, POV.LST, POV.ERR and POV.HEX,
POV.HEX We are only interested because it is the we have to use the program to load the microcontroller (in the case that we are not successful compilation of the POV.HEX not created us but we will have to enter the POV.ERR to see the mistakes we have.
now show you how Hexadecimal is the code to transfer to the CIP.


Now we just need to use a transferred program that will depend on the hardware interface is used, for example, ICPROG, PonyProg, WINPIC, UPP628, IDC2, etc ... intefdace and hardware that can be for LPT port, or Serial or USB.

NOTE: cost me a bit up because it messes up the code a bit, just as I upload them here. Asm if you are interested to do or see well.

http://www.mediafire.com/?ydb5y3b6e3ljutg



0 comments:

Post a Comment