MOVLW 0x07 ; RA3-RA0 are
MOVWF TRISA ; outputs
Hello there. I've just started to read the PIC16F628 datasheet/manual and I started to understand some concepts. Of course, there are some doubts,
Hope it helps.1- What is the prescaler? What is his funtion and for what it's usefull?
An example will be good. Let's say the PIC is running at 4MHz, so each instruction cycle is 1µs. Say if the internal timer run from internal clock, so it takes 256µs for the timer to run from 0 to 255 (8-bit). If the timer is prescaled, say 1:2, then 512µs is taken for the timer to run from 0 to 255.
2- For what are those register and how usefull they are (I know that they are explained in the datasheet, but there are some stuff's that I can't understand - I'm not english native speaker, because the expressions used are too technical, so if are you guys telling by your words, I might understand better):
-STATUS
-the status of the PIC. Example: after performing 7-7, the result is 0 so the Z bit of this register is set.
-OPTION
-some settings for PORTB, timer0, external interrupt
-INTCON
-enable or disable the interrupt, or read which interrupt has occurred with this register
-PIE1
-there're many sources of interrupt, so one register (INTCON) cannot control that much, this peripheral interrupt enable register is used to enable or disable some other interrupt
-PIR1
-used to read which interrupt of PIE1 has occurred
-PCON
-besides changing the internal oscillator frequency, this is used to check what type of reset has occurred, POR or BOR
-PCL and PCLATH
-program counter register. since this is 14-bit core, a 8-bit register is not enough for it, so 2 register is used (PCL and PCH). PCLATH is the latch of PCH. read page 28
3- What is the function of TMR0? Why we need to select for example, TMR0 1:2 WDT 1:1, TMR0 1:4 WDT 1:2? What differences it makes?
TMR0 is just a 8-bit timer. It can be used for counting, intertupt, etc. The scaling is explained above, same to the prescaling of WDT.
4- What this means (there are lot's of stuffs like this in the manual):
PORTB<7:4> Inputs ; PORTB <3:00> (pag.42 of PIC16F628 datasheet)
AtomSoft has explained.
5- I'd like to know too what means this MOVLW 0x07 (well in part I know what means, but I do not understand why is written like that 0x07. Basicly what means the 0x07? is equivalent to 07h? what is the difference to write in one way and another?)
0x07 is hex of 7
d'7' or .7 is decimal of 7
b'00000111' is binary of 7
Here is another: 0xC0.. - where can I locate this on the PIC memory?
Movlw 0xA6 (the same) pag 60...
6- Another notation used in the datasheet to identify something that I cannot figure it out..
CCP1M3:CCP1M0 (CCP1CON<3:0> (pag 62) What this means? Is some way to identify a place on something? Where?
Explained by AtomSoft
7- Another example is the PWM formula, on pag 65..
there are some codes like the previows one, CCPR1L:CCP1CON<5:4> * Tosc (..).. what that means?
Tosc is the oscillator period, with 4Mhz, it is 0.25µs
... the number 0xC0 (in this case 120? In binary 0111 1000, right?)
You should avoid setting your config bits with a number like that. It tells you nothing about which bits you have on or off. Use the mnemonics. Page 92 of the datasheet (section 14.1) explains what each bit does.btw:
__config 0x3D18 ;sets the configuration settings
;(oscillator type etc.)
Sets the config settings, but wich config settings? Where can I see those config sets made by the 0x3D18? I've searched in the datasheet but i didn't found it..
__config _HS_OSC & _WDT_OFF & _LVP_OFF
After work. You're in a different time zone.no one?
Best regards
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
end
I don't think you've quite got it into your head just how fast 4MHz is. A PIC at 4MHz is doing just shy of 1 million instructions per second. A single byte counter would count down so fast you wouldn't even notice the delay.Could someone explain me why we need the count a and count b? The count 1 wouldn't be enough?
cblock
d1
d2
endc
Delay
;249993 cycles
movlw 0x4E
movwf d1
movlw 0xC4
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
Here's a typical assembly program first three lines:which are the differences between using the #include <pic.inc> and using the LIST <pic> ?
list p=18F1320
include <p18f1320.inc>
CONFIG OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF
That's the usual layout. You configure any registers that you're going to use in your program, or that would affect what you're going to use. Once that's set up, you start actually doing things.then (here is the doubt) we set all the basic configurations to the PIC like I/O ports, digit/analog ports.. etc.. and then is the main routine.. right?
There is any kind of pattern to do the program structure? Can someone tell me?
Rather than use equ's for variable definitions, use cblock. Like this:I have here a program, and in somewhere I find this: counter equ 0x20. This means that in the GPR will reserve a memory space that will save the data into that location?
cblock 0x00
char,numr,bitnum,loop1,loop2,temp1,d1,d2,d3,iflag
endc
Kind of, but not nearly so complex. Cblock just reserves space in RAM and sets some labels to point to the variables. What kind of variable you store there is up to you. Your brain is the compiler when working in assembly.Is something like C when we do INT <name> or CHAR <name>
Umm... Each part of what?Could you comment and explain each part?
LIST p=16F819
include "P16F819.inc"
__config _INTRC_IO & _WDT_OFF & _LVP_OFF
cblock 0x20 ;start of general purpose registers
d1,d2,d3
endc
org 0x0000
init
banksel OSCCON ;bank 1
movlw b'01110000' ;set 8MHz osc
movwf OSCCON
clrf TRISB
banksel PORTA ;bank 0
main bsf PORTB,0
call delay
bcf PORTB,0
call delay
goto main
delay movlw 0x3f
movwf d1
movlw 0x9d
movwf d2
delay_0 decfsz d1,f
goto dd3
decfsz d2,f
dd3 goto delay_0
return
end
It actually takes longer than that because it's doing a lot more than you're thinking. Follow the flow closely. It decrements d1 until it's zero. Then it decrements d2 by one and starts decrementing d1 until zero again (d1 has wrapped around and become 255 again). Then it decrements d2 by one and does d1 again. It keeps doing this until d2 reaches zero. Then it wastes a few cycles to pad out the delay to exactly 250ms.Each part of the block that you have just written. The most confusing thing for me is understand what means loading the 0x4E and 0xC4 to the d1 and d2.
The decfsz says decrement file, skip if it's zero..
Well 0x4E is 78 in decimal.. so he will decrement the d1 until he reach 0 when he reach 0 he skip the goto $+2 part and start decrementing the d2 until reach again 0 .. this means that he as just spent 78+196 cycles doing the decrement? Each cycle takes 1uS to complet.. so he as just spent 274 uS and not 250mS.. are you following ?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?