Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (781.3 KB, 33 trang )
<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">
<b>DIVISION OF ELECTRONICS-TELECOMMUNICATIONS</b>
Edited by Division of Electronics-Telecommunication (Internal only)
</div><span class="text_page_counter">Trang 2</span><div class="page_container" data-page="2">2
<b>UNIT OBJECTIVE </b>
Students know how to use Proteus software to draw circuit
To use to simulate the circuit, microcontroller circuits as PIC16F877A
The circuit diagram.
</div><span class="text_page_counter">Trang 3</span><div class="page_container" data-page="3"><b>3) The steps for creating simulation circuit run in Protues </b>
Step 1: Get in Protues components.
Method 1: Press the P button on the keyboard. Method 2: Press icon P on interface
Terminals
4
Name of device
Name of components
</div><span class="text_page_counter">Trang 5</span><div class="page_container" data-page="5">Step 3: Connect wires
Step 4: For running the application circuit.
<b>Exercise 1: Insert the following circuit in Protues </b>
6
<b>Exercise 2: Change the variable resistor R3, use the oscilloscopes to measure waves (Get in the </b>
instrumentation see the previous section)
<b>Exercise 3: </b>
<small>RC1/T1OSI/CCP2</small> <sup>16</sup><small>RC2/CCP1</small> <sup>17</sup><small>RC3/SCK/SCL</small> <sup>18</sup>
<small>RD0/PSP0</small> <sup>19</sup><small>RD1/PSP1</small> <sup>20</sup><small>RB7/PGD</small> <sup>40</sup><small>RB6/PGC</small> <sup>39</sup><small>RB5</small> <sup>38</sup><small>RB4</small> <sup>37</sup><small>RB3/PGM</small> <sup>36</sup><small>RB2</small> <sup>35</sup><small>RB1</small> <sup>34</sup><small>RB0/INT</small> <sup>33</sup>
<small>RD7/PSP7</small> <sup>30</sup><small>RD6/PSP6</small> <sup>29</sup><small>RD5/PSP5</small> <sup>28</sup><small>RD4/PSP4</small> <sup>27</sup><small>RD3/PSP3</small> <sup>22</sup><small>RD2/PSP2</small> <sup>21</sup><small>RC7/RX/DT</small> <sup>26</sup><small>RC6/TX/CK</small> <sup>25</sup><small>RC5/SDO</small> <sup>24</sup><small>RC4/SDI/SDA</small> <sup>23</sup><small>RA3/AN3/VREF+</small>
<small>RC0/T1OSO/T1CKI</small> <sup>15</sup><small>MCLR/Vpp/THV</small>
</div><span class="text_page_counter">Trang 7</span><div class="page_container" data-page="7">8
<b>Exercise 4: </b>
10
<b>UNIT OBJECTIVE </b>
Students know how to:
Students know how to use Proteus software to draw circuit To use to simulate IN/OUT on microcontroller as PIC6F877A Implement circuit on experimental kit
// Program for display from 00 to 99 #include<16f877.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000) // define crystal = 4MHz
Const char MA7D[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; void main()
{
int chuc,dv,i,z; set_tris_d(0x00); set_tris_b(0x00); while(true) {
for (i=0; i< 100; i++) {
Chuc=i/10; dv=i%10; z=MA7D[chuc]; Output_b(z); z=MA7D[dv]; Output_d(z); Delay_ms(300); }
} }
<b>Exercise 2: The students Students connect the circuit as shown below, writing program number </b>
65535
</div><span class="text_page_counter">Trang 12</span><div class="page_container" data-page="12">12 #include <7_seg.h>
#define Data PIN_B0 //dinh nghia chan du lieu cho 595 #define sh PIN_B1 //dinh nghia chan SH cho 595 #define st PIN_B2 //dinh nghia chan ST cho 595
//ma led 7 doan co dau cham nam o tren
unsigned char ma[10]={0x81,0xed,0xc2,0xc8,0xac,0x98,0x90,0xcd,0x80,0x88}; //ma led 7 doan co dau cham nam o duoi
unsigned char ma1[10]={0x18,0x7b,0x2c,0x29,0x4b,0x89,0x88,0x3b,0x08,0x09}; //mang chua cac so can hien thi len led 7 doan
unsigned char so[6]={0,1,2,3,4,5};
unsigned char sec, min1, hr,luu;
int1 en; //bien giup cho hieu ung chop tat dau :
//chuong trinh tach lay so de hien thi void Transform_Number(int16 value) {
so[1]=value/10000; //so hang van so[2]=(value-so[1]*10000)/1000;//so ngan so[3]=(value-so[1]*10000-so[2]*1000)/100;
so[4]=(value-so[1]*10000-so[2]*1000-so[3]*100)/10; so[5]=value%10;
}
//chuong trinh dich du lieu ra 595 void send_595(unsigned char da) {
signed char i; for(i=7;i>=0;i--) {
output_bit(Data,(da>>i)&0x01); output_bit(sh,0);
output_bit(sh,1); }
send_595(~(1<<(i+1)));
temp=((i%2)==0)? ma[so[i]]:ma1[so[i]]; //chon ma led 7 doan thich hop if(((i==1)||(i==3))&&(en==1)) temp&=0xf7; //hien dau cham ngan cach if(((i==2)||(i==4))&&(en==1)) temp&=0x7f; //hien dau cham ngan cach send_595(temp);
output_bit(st,0); output_bit(st,1); delay_ms(1);
</div><span class="text_page_counter">Trang 13</span><div class="page_container" data-page="13">
send_595(0xff); send_595(0xff); output_bit(st,0); output_bit(st,1); delay_us(100); }
}
void main() {
signed char i;
// TODO: USER CODE!! set_tris_b(0x00);
while(true) {
Transform_Number(65535); //lam dau : chop tat
if(luu!=sec)en=~en; luu=sec;
//---
for(i=0;i<10;i++)display(); }
</div><span class="text_page_counter">Trang 14</span><div class="page_container" data-page="14">14
<b>UNIT OBJECTIVE </b>
Students know how to:
<b>Exercise 1: Students draw the circuit as shown below, write the program run string "MATRIX </b>
8x16"
#include <16f877a.h>
#fuses NOLVP,NOWDT,PUT,HS #use delay(clock=20000000) #BIT PORTCbits_RC0 = 0X07.0 #BIT PORTCbits_RC1 = 0X07.1 #BIT PORTCbits_RC3 = 0X07.3 const unsigned char font[] = {
127, 127, 14, 28, 14, 127, 127, 0, //'M' 124, 126, 19, 19, 126, 124, 0, 0, //'A' 3, 65, 127, 127, 65, 3, 0, 0, //'T' 65, 127, 127, 9, 25, 127, 102, 0, //'R' 0, 65, 127, 127, 65, 0, 0, 0, //'I'
</div><span class="text_page_counter">Trang 15</span><div class="page_container" data-page="15">67, 103, 60, 24, 60, 103, 67, 0, //'X' 0, 0, 0, 0, 0, 0, 0, 0, //' ' 54, 127, 73, 73, 127, 54, 0, 0, //'8' 68, 108, 56, 16, 56, 108, 68, 0, //'x' 64, 66, 127, 127, 64, 64, 0, 0, //'1' 60, 126, 75, 73, 121, 48, 0, 0, //'6' 0, 0, 0, 0, 0, 0, 0, 0, //' ' 0, 0, 0, 0, 0, 0, 0, 0, //' ' };
void main() {
unsigned rol, delay, col; SET_TRIS_B(0x00); SET_TRIS_C(0x00); OUTPUT_B(0x00); OUTPUT_C(0x00); while(1)
{
for(rol=0;rol<112;rol++)
{ //font. 13 x 8[8x8 matrix] = 112. for(delay=0;delay<20;delay++) {
PORTCbits_RC0 = 1; PORTCbits_RC0 = 0; PORTCbits_RC1 = 1; PORTCbits_RC3 = 1; PORTCbits_RC3 = 0;
for(col=0;col<16;col++) // 16 hang va cot {
OUTPUT_B (~ font[col + rol]); delay_us(300);
PORTCbits_RC0 = 1; PORTCbits_RC0 = 0; PORTCbits_RC1 = 0; PORTCbits_RC3 = 1; PORTCbits_RC3 = 0;
} } } }
}
<b>Application exercises: </b>
<b>Exercise 2: Write a program that runs the string "LOP VIDIEUKHIEN" from right to left. Exercise 3: Write a program that runs the string "DH TON DUC THANG" from left to right. </b>
</div><span class="text_page_counter">Trang 16</span><div class="page_container" data-page="16">16
<b>UNIT OBJECTIVE </b>
Students know how to:
<small>74LS595Q0</small> <sup>15</sup>
<small>Q1</small> <sup>1</sup><small>Q2</small> <sup>2</sup><small>Q3</small> <sup>3</sup><small>Q4</small> <sup>4</sup><small>Q5</small> <sup>5</sup><small>Q6</small> <sup>6</sup><small>Q7</small> <sup>7</sup><small>Q7'</small> <sup>9</sup><small>SH_CP11</small>
<small>RC1/T1OSI/CCP2</small> <sup>16</sup><small>RC2/CCP1</small> <sup>17</sup><small>RC3/SCK/SCL</small> <sup>18</sup>
<small>RD0/PSP0</small> <sup>19</sup><small>RD1/PSP1</small> <sup>20</sup><small>RB7/PGD</small> <sup>40</sup><small>RB6/PGC</small> <sup>39</sup><small>RB5</small> <sup>38</sup><small>RB4</small> <sup>37</sup><small>RB3/PGM</small> <sup>36</sup><small>RB2</small> <sup>35</sup><small>RB1</small> <sup>34</sup><small>RB0/INT</small> <sup>33</sup>
<small>RD7/PSP7</small> <sup>30</sup><small>RD6/PSP6</small> <sup>29</sup><small>RD5/PSP5</small> <sup>28</sup><small>RD4/PSP4</small> <sup>27</sup><small>RD3/PSP3</small> <sup>22</sup><small>RD2/PSP2</small> <sup>21</sup><small>RC7/RX/DT</small> <sup>26</sup><small>RC6/TX/CK</small> <sup>25</sup><small>RC5/SDO</small> <sup>24</sup><small>RC4/SDI/SDA</small> <sup>23</sup><small>RA3/AN3/VREF+</small>
<small>RC0/T1OSO/T1CKI</small> <sup>15</sup><small>MCLR/Vpp/THV</small>
<small>X1</small> <sup>1</sup>
<small>X2</small> <sup>2</sup><small>SCL6</small>
18
#fuses HS,NOWDT,PUT,NOPROTECT #use delay (clock = 20000000)
#include <LCD.c> int8 nhietdo=0; void main() {
set_tris_d(0); lcd_init();
</div><span class="text_page_counter">Trang 21</span><div class="page_container" data-page="21">delay_ms(10);
setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(AN0_AN1_AN3 ); set_adc_channel(0);
delay_us(10); while(1) {
int1 done = adc_done(); while(!done) {
done = adc_done(); }
nhietdo = read_adc(); lcd_gotoxy(1,1);
printf(lcd_putc,"nhiet do la : %d%d",nhietdo/10,nhietdo%10); }
<b>Applicative Exercises: </b>
<b>Exercise 2: Integrated LCD module, retrieve the value from the a variable resistor voltage </b>
displayed on the LCD.
<b>Exercise 3: Use of PIC ADC module to measure the temperature in the room, use the LCD to </b>
display temperature value with LCD-mode of 8 bits as follows:
</div><span class="text_page_counter">Trang 22</span><div class="page_container" data-page="22">The structure of the keyboard is as follows:
<b>Exercise 1: Write a program to retrieve data from a keypress and then displays the binary </b>
value of the key press on the single LED.
</div><span class="text_page_counter">Trang 23</span><div class="page_container" data-page="23">// Program for Exercise 1
#include <16F877A.h> #include <key_4x4.c>
#use delay(clock=20000000)
void main() {
unsigned int8 key; set_tris_b(0x00); key_4x4_init();
while(TRUE) {
key=get_key_4x4(); if(key)
{
output_b(key-48);
while(key)key=get_key_4x4(); }
delay_ms(10); }
#ifndef __KEY_4X4_ #define __KEY_4X4_
static unsigned char KEY_4X4[4][4]={'7','8','9','/', '4','5','6','*',
'1','2','3','-', '#','0','=','+'}; void key_4x4_init(void)
{
output_drive(ROW1); output_drive(ROW2); output_drive(ROW3); output_drive(ROW4); output_float(COL1);
</div><span class="text_page_counter">Trang 24</span><div class="page_container" data-page="24">24 output_float(COL3);
output_float(COL4); }
int1 ButtonIsPush(void) {
output_low(ROW1); output_low(ROW2); output_low(ROW3); output_low(ROW4);
if((input(COL1)==0)|(input(COL2)==0)|(input(COL3)==0)|(input(COL4)==0)) return 1;
else return 0; }
void check_row(unsigned char i) {
output_high(ROW1); output_high(ROW2); output_high(ROW3); output_high(ROW4); if(i==0)
{
output_low(ROW1); }
else if(i==1) {
output_low(ROW2); }
else if(i==2) {
output_low(ROW3); }
else {
output_low(ROW4); }
}
unsigned char get_key_4x4() {
unsigned char i; if(ButtonIsPush()) {
delay_ms(5); if(ButtonIsPush()) {
for(i=0;i<4;i++) {
check_row(i);
if(!input(COL1)) return KEY_4X4[3-i][0]; if(!input(COL2)) return KEY_4X4[3-i][1]; if(!input(COL3)) return KEY_4X4[3-i][2]; if(!input(COL4)) return KEY_4X4[3-i][3]; }
</div><span class="text_page_counter">Trang 25</span><div class="page_container" data-page="25">} }
return 0; }
</div><span class="text_page_counter">Trang 26</span><div class="page_container" data-page="26">