Issuu on Google+

4. ภ  ภ Proteus   RTC ภ ! "#$%&#!$ 1) ภ  ภ Proteus ภ   ภ

 4.1 ! "#$ภ  ภ

 4.2 ! "$  ภ Proteus 7.2


2) ภ/0 1$2ภ34 (Device) :ภ;0ภ2< P =!1"$ Device 

 4.3 ! ภ/0 $2ภ34 3) ภ;?$ภDevice :1 ภภ;?$ภ?$ 

$ ;;$4 PIC $4 PIC16F628A :=F$ Category ;?$ภMicroprocessor ICs !1=F$ Sub-Category ;?$ภPIC 16 Family ภ#ภภ;0ภ PIC16F628A  Q! 

 4.4 ! ภ;?$ภDevice 

$ ;;$4 PIC $4 PIC16F628A


4) ภ#ภ;?$ภF0 1Q"$ PIC16F628A  2 "1 ; $: 3 F0  ; 

 4.5 ! F0 1Q"$ PIC16F628A 5) ภ/0 $2ภ34 

$2ภ34 PIC 16F628A MAX 232 DS 1307 DS 1820 (=F DS1822) CRYSTAL CELL 1.5 V Button Capacitors 10 P Resistors10K Resistors 4.7K

 4.6 ! :F?$$2ภ34 S (Category) Microprocessor ICs Microprocessor ICs Microprocessor ICs Data Converters Miscellaneous Miscellaneous Switches & Delay Capacitors Resistors Resistors

1 1 1 1 1 1 1 1 6 2 2


6) ก/0 Power 5 1;4 ; Ground 

 4.7 ! =!1"$ Power ; Ground 7) /0 1 Virtual Terminal /?$ก ! d;ก0 $d RS-232 

 4.8 ! ก/0 Virtual Terminal


8)  ?$$2ก34# 1 ;1  

 4.9 ! ก$2ก34# 1 9) ก#กF?$ $$2ก34 :ก;0กf: !4"$2ก34ก#ก;ก ;1 ;0ก:$กF?$ $กd0 /; $ก;=ก;0ก"12 #  ก ก ;$2ก34?$!F?$ $2ก34 ก;1

 4.10 ! F?$ $$2ก34!:$:


'! ( Edit Windows /01 2& &#!$ • ก 1 - ;0กf:F?$1$ก ;1;0กf: State ;1;0 "1/?$:2 ก1$234 • ก ก"23! 0 - ;0ก"11$2ก34  ?$g! =;0กf:/?$ ก"23! 0 • ก$!F?$

- ?$ก$!:h$ ;0ก2 0 ;;0ก2 ;:/?$$12 !$2 - Q$ก;ก!F?$ ก 2 ;:i 2 ก;ก!F?$ ;1;0ก2 $ก ก 2 ;1;ก!F?$ $ก?$: i ;1 0;;0กกก0 dot gก!0#!2 • ก;$$ก - ;0ก"1 ;1ก Delete - ?$;0ก"1 2 1$2ก34 - ก;$2ก34;:1=F !4 ;0กf:;ก;2 013$ก; ;1ก Delete • ก:: :1 - ;0ก"1 1 # ;;0กf:$2ก34 ;1;ก: $ก • ก::gก;2

- ;0กf:;ก;?$ก$2ก34ก;2 $ก:: ก 2< g!j;กk34ก:: ก#ก::  ก0 10) ก;?$ก CPU 

$ ;;$4 :ก;0ก"1ก#;0กf:$ก  23! 0"$

$ ;;$4 /?$กก !jj3m0ก ; PATH "$ h;4 !ก2; .HEX $ก;$ก

 4.11 ! กh;4  ก " =F1 fo  !ก2; HEX


11) ภภ 23! 0"$ Virtual Terminal ;1ภOK 

 4.12 ! ภภ 23! 0"$ Virtual Terminal 12) ภ#0 ;$ภ :ภ;0ภ2< Play 

 4.13 ! 2< ภ 13) ! d;ภ  ภ Proteus 7.2

 4.14 ! d; ?$ภภ2< Play


14) ก Set Font Virtual Terminal

 4.15 ก Set Font Virtual Terminal 15) Source Code CCS C - **Code Ds1307 #define DS1307_SDA PIN_B4 #define DS1307_SCL PIN_B3 #use i2c(master, sda=DS1307_SDA, scl=DS1307_SCL) //========================== // initial DS1307 //========================== void init_DS1307() { output_float(DS1307_SCL); output_float(DS1307_SDA); } //========================== // write data one byte to // DS1307 //========================== void write_DS1307(byte address, BYTE data) { short int status;


i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_write(data); i2c_stop(); i2c_start(); status=i2c_write(0xd0); while(status==1) { i2c_start(); status=i2c_write(0xd0); } } //========================== // read data one byte from DS1307 //========================== BYTE read_DS1307(byte address) { BYTE data; i2c_start(); i2c_write(0xd0); i2c_write(address); i2c_start(); i2c_write(0xd1); data=i2c_read(0); i2c_stop(); return(data); }


-**Code Ds1820 #BYTE TRISA=0x85 #BYTE PORTA=0x5 #BYTE STATUS=0x3 #define RP0 5 #define C 0

// The following are standard 1-Wire routines. void make_ds1820_high_pin(int sensor) { TRISA = 0xff; } void make_ds1820_low_pin(int sensor) { PORTA = 0x00; TRISA = 0xff & (~(0x01 << sensor)); }

// delay routines void delay_10us(int t) { #asm BCF STATUS, RP0 DELAY_10US_X: CLRWDT NOP NOP NOP NOP


NOP NOP DECFSZ t, F GOTO DELAY_10US_X #endasm } void delay_ms(long t) // delays t millisecs { do { delay_10us(100); } while(--t); } void init_ds1820(int sensor) { make_ds1820_high_pin(sensor); make_ds1820_low_pin(sensor); delay_10us(50); make_ds1820_high_pin(sensor); delay_10us(50); } int read_ds1820_one_byte(int sensor) { int n, i_byte, temp, mask; mask = 0xff & (~(0x01<<sensor)); for (n=0; n<8; n++) { PORTA=0x00;


TRISA=mask; TRISA=0xff; #asm CLRWDT NOP NOP #endasm temp=PORTA; if (temp & ~mask) { i_byte=(i_byte>>1) | 0x80; // least sig bit first } else { i_byte=i_byte >> 1; } delay_10us(6); } return(i_byte); } void write_ds1820_one_byte(int d, int sensor) { int n, mask; mask = 0xff & (~(0x01<<sensor)); for(n=0; n<8; n++) { if (d&0x01) { PORTA=0; TRISA=mask; // momentary low TRISA=0xff;


delay_10us(6); } else { PORTA=0; TRISA=mask; delay_10us(6); TRISA=0xff; } d=d>>1; } } int16 read_sensor(byte sensor) { int16 t1; int buff[9], n,temp,temp_dec; init_ds1820(sensor); write_ds1820_one_byte(0xcc, sensor); write_ds1820_one_byte(0x44, sensor); while (read_ds1820_one_byte(sensor)==0xff); init_ds1820(sensor); write_ds1820_one_byte(0xcc, sensor); write_ds1820_one_byte(0xbe, sensor); for (n=0; n<9; n++) { buff[n]=read_ds1820_one_byte(sensor); // read DS1820 } temp=buff[0]>>1; if ((buff[0] & 0x1)==1) temp_dec=5;


else temp_dec=0; t1=temp; t1=(t1<<8) | temp_dec; // 0xTT0D return(t1); } - Code Main #include "16F628A.h" #use delay(clock=4000000) // Use Clock Speed (Hz) #fuses NOWDT // NO Wetchdog Timer; #fuses XT // LP => Oscillator Mode LP ( =F1 Q  < 200 kHz ) ; XT => Oscillator Mode TX ( =F1 Q  ก0 4 MHz ) ; HS => Oscillator Mode HS ( =F1 Q #  4 MHz "o# ) ; #fuses NOPUT // NO Power Up Time ; // #fuses NOLVP

// NO Low Voltage Program ;

#fuses NOPROTECT // NOPROTECT => Code Not Protect form Reading (  ‰$กกกŠ$ ) ; PROTECT => Code Protect form Read ( ‰$กกกŠ$); #use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B2) #include "ds1820.c" #include "ds1307.c"

// :ก=Fh‹ก4Fก4"$ DS1820; // :ก=Fh‹ก4Fก4"$ DS1307;

// Use Serial I/O Port RS232 ;


void main(void) { int8 i,sec,min,hour,day,date,month,year; // ภ 1  F0 1;" 8 0 (0-256) nt16 tpx,all_tp; // ภ 1  F0 1;" 16 0 (0-65,535) int8 tp,tpd; delay_ms(50); init_ds1307(); // initial DS1307; sec=read_ds1307(0); write_ds1307(0,sec & 0x7F); // enable oscillator(bit 7 =0); while(true) { printf("/////////////////////Real Time Clock ///////////////////\r\n"); sec=read_ds1307(0); // read second; min=read_ds1307(1); // read minute; hour=read_ds1307(2); // read hour; day=read_ds1307(3); // read day; date=read_ds1307(4); // read date; month=read_ds1307(5); // read month; year=read_ds1307(6); // read year; printf("---> Day : %02X\r\r\n\n",day); printf("---> Time : %02X:%02X:%02X\r\r\n\n",hour,min,sec); printf("---> Date : %02X/%02X/20%02X\r\r\n\n",date,month,year); for (i =0;i<5;i++) { all_tp=read_sensor(i); // read temperature; tpx=all_tp; tp=make8(tpx,1);


tpx=all_tp; tpd=make8(tpx,0); printf("Ch:%u = %03u.%u\r\r\n",i+1,tp,tpd); } delay_ms(500); printf("================================================\r\r"); } }


Rtc simulator with proteus