Professional Documents
Culture Documents
17
Home
Become a subscriber (Free)
Projects
Join 29,000 other subscribers to receive subscriber sale
Arduino
discounts and other free resources.
MAX7219 Dotmatrix Name: Your First Name
DS18B20 Thermometer
Humidity DHT22/11
Don't worry -- youre-mail address is totally secure. I
Rotary Encoder
promise to use it only to send you MicroZine.
MAX6675 0 to 1024 DegC
TRAVEL
Battery Charger Back 12F675 Tutorial Index Next MORE,
SSD1306 OLED FEEL
BACK TO
MORE! TOP
OPEN
Resources
A Real Time
Tips & Techniques Clock design
PIC Tutorials
(DS1307) with
Sidebar
a PIC
Microcontroller Blog microcontroller
Site map I/O Port usage summary PORT register: TRISIO - The port direction register.
Real Time Clock
Design (FREE): A Free
Other You can reset bits (low) to define port pins as outputs.
and Complete RTC
You can set bits (high) to define port pins as inputs.
Articles design using the
DS1307 and a PIC
Books PORT register : GPIO - The input/output register.
micro (16F88) also
re-targetable. This
You write to this register to set output pins high or low.
PIC project uses an
You read from this register to read the current value input pins.
I2C Clock chip and 7-
segment display to
All of these actions were used in the previous two tutorial pages and the all work using
create a fou…
bit values:
Read more
TRISIO = 0x01; sets bit 0 of TRISIO all the rest zero.
TRISIO = 0x04; sets bit 2 of TRISIO all the rest zero.
GPIO = 0x01; sets bit 0 of GPIO all the rest zero. How to use the
25 GPIO = 0x04; sets bit 2 of GPIO all the rest zero. ADXL345 for
Male
movement
Note: In other PIC devices ports are labeled alphabetically and they do not use the sensing and
GPIO name instead they use the text 'PORT'. So the first port is labeled PORTA the more.
No next PORTB etc. Corresponding port direction registers are TRISA and TRISB. You can
use them in exactly the same way as GPIO and TRISIO.
Rs. 547
The circuit uses the standard MAX232 level translator chip but you could use an Read more
SP202ECP which has identical pin out (and is cheaper!) and lets you use 100nF
capacitors instead of electrolytic ones. You can also use USB to RS232 or USB to
Serial Digital converters and with these you don't even need the MAX232 level
Easy Switch
converter everything is done at 5V (or 3V3)..
Debounce
Connect the ground and transmit output to a serial port connector as shown and
to a serial cable from it to the PC and it's ready to go.
Switch debounce:
Solderless breadboard Three different ways
to debounce input
Add the MAX232 Chip and capacitors.
push switches with
one amazing method
that you can't miss.
Read more
Read more
Readers Comments
- Ranish Pottath
Learn about the tool used for creating this diagram.
"This site really is
- Milan
bursach<at>gmail.com<
"Awesome site,
very, very easy and nice
to navigate!"
- Matt
matt_tr<at>
wolf359.cjb.net
Learn Microcontrollers
"Interested in
Microcontrollers?"
FREE GUIDE :
CLICK HERE
- Dave
de_scott<at>bellsouth.net
- Suresh
integratredinfosys<at>
yahoo.com
25
No
Rs. 547
Software
OPEN
//////////////////////////////////////////////////////////////////////
void _Soft_USART_Write(unsigned short chr) {
unsigned short mask=1,i;
unsigned int txdata;
// 10 output bits
for (i=0;i<9;i++) { // lsb 1st 8 bits
if (mask & txdata) {
asm {CLRW}
SU_set; // output low for logic 1
} else {
SU_res;// output high for logic 0
asm {CLRW}
}
mask <<=1;
delay_us(395); // 2400 simulate to calibrate the loop.
}
The character to transmit is shifted left one bit into the data variable which acts a
serial shift register.
Using 'data' in this way lets the routine evaluate in a constant time without
having to check an index to do a different action so for higher (more critical)
speeds it works better.
The stop bit (10th bit) is a delay with the output set high.
Note: You need to calibrate the loop by timing from SU_Set to the next SU_set
or SU_res if you change the baud rate.
Note: The advantage of using the hard coded timing is that the routine only takes
up about 90 words.
If you don't need an accurate clock then the part will still work without using the
OCSCAL value - it will just be inaccurate.
OPEN
Note: The factory setting of the oscillator is 1% which is good enough. So if you
have not overwritten it (easily done) then don't change it.
You can either create a simple assembler file with the following sort of code:
org 0x3ff
Replay
Note: It is not worth trying to code the value into the C source as it will use a non-
standard method of programming.
Alternatively download winpic800 (look online to download it) and set the device to
12F675, load up the hex file and go to the memory location in winpic800 and type in
the last location the value 34 followed by the CAL value you have previously stored.
Save the file.
1.
After setting the CAL value into the hex file (as above).
2.
Create a pre-built project with your device (12F675).
3.
In MPLAB X Select Menu File-->Project Properties.
4.
Click your programmer (mine is PICkit3).
5.
In the top dropdown box select: Program Options.
6.
Tick the check the box labeled "Program calibration memory".
7.
Now program the device as usual.
8.
Read back the hex data (use MPLAB X upload)
9.
Then view program memory Menu: Window-->Pic Memory Views--
>Program Memory.
10. Scroll to bottom and check the CAL value at the last location.
11. Now go back to the project Options and turn off "Program calibration
memory" which will now be protected (until you lose it again!).
You can check it worked by re-building the original hex file (so the manually
inserted CAL value is lost). Re-program this new hex into the PIC. Then upload
the hex data. View memory as above and scroll to bottom - the new CAL value
will be there.
OSCCAL settings
This register changes the oscillation frequency when you write to it
Only the upper six bits are used as the calibration bits so values must be different
by 4 to change to the next OSCCAL setting e.g. values 32,33,34 and 35 would
give the same frequency setting.
Important
You have to write and use a routine to set the register OSCAL with the stored
value : It is not done automatically for you!
The code the data sheet suggests you use to set the calibration value into the
OSCCAL register is :
All this does is call the location that contains the RETLW value which then returns the
calibration value. This assembler code is packaged into the get_set_osc_cal() routine
and does the OSCCAL setting for you.
Note: If the value stored at location 0x3ff is zero the oscillator may not work so -don't
call this function if the CAL value is corrupted.
Use a frequency counter to measure the output (you can find a project on this
site here). Change the OSCCAL value until you find the one closest to 1MHz.
To get the value back into the 12F675 use ICPROG and put the hex code RETLW
instruction at address 0x3FF. The first byte of the instruction is 0x34 and the
second is the value returned so for a calibration value of 0x20 you would put:
Note: See the tip for storing the calibration value so you will never forget it or
loose it again.
New! Comments
Have your say about what you just read! Leave me a comment in the box
below.
Add a comment...
Chisanga Mumba
I can't download it.
Like · Reply · 3y
Abu Hassan
THANKS I ENYOY YOUR TUTORIAL
Like · Reply · 2y
Prashant Chavan
wow
Like · Reply · 2y
Kalaiselvan Kaliyaperumal
nice concept
Like · Reply · 2y
Tanbir Ahammed
thanks
Like · Reply · 2y