M. Amer Iqbal Qureshi



tải về 3.06 Mb.
Chế độ xem pdf
trang126/132
Chuyển đổi dữ liệu09.12.2022
Kích3.06 Mb.
#53945
1   ...   122   123   124   125   126   127   128   129   ...   132
Amer Iqbal - Teach Yourself PIC Microcontrollers for Absolute Beginners-Microtronics Pakistan (2001)

    Điều hướng trang này:
  • Symbol
Device 
18F452 
XTAL
=20 
ALL_DIGITAL 
true 
LCD_DTPIN 
PORTD
.4 
LCD_RSPIN 
PORTD
.3 
LCD_ENPIN 
PORTD
.2 
Symbol TMR0_ON 
T0CON
.7
' 1=Enable timer 0=disable 
Symbol TMR0_8bit 
T0CON
.6
' 1= 8 Bit, 0=16 Bit 
Symbol TMR0_CS 
T0CON
.5
' Clock Source 1=RA4 pin, 0=internal oscillator 
Symbol TMR0_SE 
T0CON
.4
' Signal Edge, Rising or falling 
Symbol TMR0_PSA
T0CON
.3
' Enable Prescalar, 1=OFF 0=ON 
Symbol TMR0_PS2 
T0CON
.2
' Prescalar settings if PSA enabled 
Symbol TMR0_PS1 
T0CON
.1 
Symbol TMR0_PS0 
T0CON
.0 
TMR0_CS =1
'Count pulses on RA4 
TMR0_8bit = 0 
' Use 16 bit counter 
TMR0_PSA = 1 
' do not use prescaler count every pulse 
 
Dim As Word 
Dim As Word 
Dim As Word 
TMR0_ON =1 
loop: 
x=0 
y.LowByte=
TMR0L 
y.HighByte=
TMR0H 
DelayMS 1000 
x.LowByte 
TMR0L 
x.HighByte=
TMR0H 
z=x-y 
Print At 1,1, 
"Frequency:"
At 2,1, DEC6 z, 
" Hz" 
GoTo loop 


Teach Yourself PIC Microcontrollers | www.electronicspk.com | 137 
want to put these two registers into 1 16bit variable. This is done by using x.HighByte  and x.LowByte
The x now contains the 16 bit count of TMR0 register. The difference of x-y is the actual count and can be 


Teach Yourself PIC Microcontrollers | www.electronicspk.com | 138 
displayed directly, as the accumulated number is the count of pulses in 1 second. The process is repeated 
again and again, to display real time frequency. 
The oscilloscope shows the pulse train, at RA4 pin, showing output of 555 timer as TTL, pulses. The figure 
below shows frequency analysis, note the main frequency to be 207.48Hz, which is fairly close to the one 
measured by our frequency counter. 
Since this frequency counter uses 16bit timer, it can measure a maximum of 65535 pulses, which will cor-
respond to 65.535KHz. A frequency beyond that will reset the counters to 0, and there is no way to deter-
mine, if this was due to high frequency or it’s the actual frequency. 
There are two ways to counteract this problem, using the same technique.
First method is to reduce the time-base, so lets say we allow half a second to count the pulses, and then 
multiply the counted pulses by 2 to get the exact frequency. This will double the frequency range, however 
resolution will also be reduced, the minimum frequency measured will be 2Hz and its multiples. However 
the upper frequency will be 131070 Hz, or 131.07KHz. Further reducing the time-base by 1/4 seconds and 
multiplying the result with 4 gives a resolution of 4Hz to 262.140KHz. 
The second method involves using pre-scalar. The pre-
scalar will divide the count by 2 to 256 depending upon 
the settings in PSA bits. If we use a prescaler of 1:2 and a 
time-base of 1 second, this will be effectively same as 1/2 
second time-base. We will have to multiply the count by 
2. if we use the prescaler to 1:256, the minimum fre-
quency will be 256 Hz and highest frequency will be, 
65535 * 256=16776960 Hz or 16776.960 KHz or 
16.776MHz. 
Thus using this simple technique, which does not involve any interrupts, we can measure up to 16MHz , 
however the higher the range, the resolution also drops. So at this frequency range, we can measure mini-
mum of 256 Hz, the next frequency would be 512 Hz. Frequencies in between can not be measured. Even 
at higher ends, the frequencies will be measured in multiples of 256. this is ok for a general purpose crude 
system, but certainly not acceptable for a professional system. 
You can think of advanced techniques, to make a more versatile professional type frequency counter, I have 
seen PIC based projects that can count from 1 MHz to 50MHz. 


Teach Yourself PIC Microcontrollers | www.electronicspk.com | 139 
LEDs are great small devices that emit light, yet do not consume much energy and do not emit heat. They 
can be arranged in many fashions, to produce visual effects, one of the most common arrangement is to put 
them in the form of a matrix, just like key pad. So if we have a matrix of 5 columns and 7 rows we have 35 
LEDs. However when put in this format they do not have 35 lines to control them, instead they are con-
trolled by 12 lines, 7 for individual row and 5 for individual columns. The LED to be lightened is controlled 
by selecting a row and column, the led at its intersection will light up. Thus by selecting the rows and col-
umns, very quickly and using persistence of vision, a number of patterns and animations can be made. 
In this section we will discuss briefly Microtronics 8x32 
matrix LED device. 
This device contains 4, 8x8 matrix LED modules, con-
nected through shift registers. The entire module therefore 
has 8 rows starting from top and 32 columns starting from 
left. 
The data is shifted one bit at a time, using Serial Parallel 
Interface, which is timed by clock signals. 
The columns are negative and rows are positive. Thus a 
logical 0 on row will lighten up the corresponding LED. 
This project is an excellent guide to understanding shift registers as well. 
In order to send 4 bytes, they are sent serially one bit at a time, along with clock signals, when all the data 
has been transferred, it is still in shift registers, to show data on pins, and therefore displays, the shift regis-
ters are sent a latch impulse. When one row is displayed, the data is again sent and before latching, the row 
counter is given a pulse, so that next row is selected. The entire process is repeated 8 times till all rows are 
displayed, remember when a new row is selected the previous row is deselected. Thus you can display one 
row at a time. After all eight rows have been scanned, the row counter is sent a reset pulse, so that row 1 is 
selected again. This process is repeated again and again, and at very rapid speed, so that it looks that all 
rows are ON at the same time. 
The connector on this board is a 10 pin connector, which is compatible with PIC-Lab-II connectors. The 
various pins in this connector are arranged as: 
The pin numbers start from left. The function of these pins is described below: 
SER is serial data in pin, which receives one bit at a time. 
CLK is the clock pin, which gets impulses to accept data on SER. 
CLR is for clearing the shift registers. 
LAT is to latch the shift register data to output lines. 
RCLK is to clock the row selection 
RST is to reset the row counter. 
GND and VCC are 5V power supply from motherboard. 
The board can have its own power supply, in that case a jumper on board has to be selected to select the 
source either Mother board or external. 
Programming The Display 
Project 2 
LED Matrix
1 2 3 4 5 6 7 8 9 10 
SER 
CLK 
CLR 
LAT 
RCLK 
RST 
GND 
VCC 


Teach Yourself PIC Microcontrollers | www.electronicspk.com | 140 
Programming the display board is simple. However it can get quite complex, when you want to display 
animations and special effects. The display itself does not stop you from any innovation. It simply requires 
that one row of data , which is 32 bits or 8 bytes be clocked into the shift register, and the appropriate row 
selected using row counter. 
The following prototype examples are only basic guidelines on using this display. We will be using BASIC 
as programming language, and PIC microcontrollers as controlling device. You may adapt these guidelines 
to your particular scenario. 
We assume following connections from microcontroller to display board and define them in our program as 
constants. 

tải về 3.06 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   122   123   124   125   126   127   128   129   ...   132




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương