rtc simulator with proteus

16
4. กก Proteus RTC ก 1) กก Proteus กก 4.1 กก 4.2 ก Proteus 7.2

Upload: saratool

Post on 06-Mar-2016

225 views

Category:

Documents


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Rtc simulator with proteus

4. ก�������ก� Proteus ������� ���� RTC ก���������� �

! "#$�%��&#��!$ 1) ���ก��������ก�� Proteus ���ก�����������������ก����������

������ 4.1 �!�"�#��$�ก��������ก��

������ 4.2 �!�������"$����ก�� Proteus 7.2

Page 2: Rtc simulator with proteus

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

Page 3: Rtc simulator with proteus

4) ��ก��#����ก���;?$กF�0��1Q��"$� PIC16F628A ����2�"1����;��� ��$:�� 3 F�0 ���;����

������ 4.5 �!�F�0��1Q��"$� PIC16F628A

5) ���ก���/0��$2�ก�34 �����

������ 4.6 �!���:F?�$$2�ก�34

$2�ก�34 ����S� (Category) ����1� PIC 16F628A Microprocessor ICs 1

MAX 232 Microprocessor ICs 1 DS 1307 Microprocessor ICs 1

DS 1820 (=F� DS1822) Data Converters 1 CRYSTAL Miscellaneous 1 CELL 1.5 V Miscellaneous 1

Button Switches & Delay 1 Capacitors 10 P Capacitors 6 Resistors10K Resistors 2

Resistors 4.7K Resistors 2

Page 4: Rtc simulator with proteus

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

Page 5: Rtc simulator with proteus

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

������ 4.9 �!�ก�����$2�ก�34��#�����1��

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

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

Page 6: Rtc simulator with proteus

� '!�����(� Edit Windows /�0�1�2&&#��!$

• ก�������1�� - �;0กf��:���F?�$��1�����$�ก�� �;�1�;0กf��:�� State �;�1�;0"1��/?�$�:2ก��1��$2�34

• ก���ก��"�23!����0 - �;0ก"1������1$2�ก�34 ��?�$��g�!���=���;0กf��:�/?�$�ก��"�23!����0

• ก����$�!���F?�$� - �?$ก����$!�:�h�����$� �;0ก����2��0���;��;0ก����2�;�:�/?�$��$���1����2!$��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���0�13�����$�ก��;��;�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 �/?�$���ก��ก����!�jj�3��m0ก� �;� PATH "$��h;4���!ก2; .HEX ��������$�ก�����;$�ก��������

������ 4.11 �!�ก������h;4���ก���"����=F������1� fo�������!ก2; HEX

Page 7: Rtc simulator with proteus

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

Page 8: Rtc simulator with proteus

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;

Page 9: Rtc simulator with proteus

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);

}

Page 10: Rtc simulator with proteus

-**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

Page 11: Rtc simulator with proteus

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;

Page 12: Rtc simulator with proteus

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;

Page 13: Rtc simulator with proteus

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;

Page 14: Rtc simulator with proteus

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 ( =F��1��Q���� < 200 kHz ) ; XT => Oscillator Mode TX ( =F��1��Q��������ก0� 4 MHz ) ; HS => Oscillator Mode HS ( =F��1��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) // Use Serial I/O Port RS232 ; #include "ds1820.c" // ���:ก=F�h��ก4F��ก4"$� DS1820; #include "ds1307.c" // ���:ก=F�h��ก4F��ก4"$� DS1307;

Page 15: Rtc simulator with proteus

void main(void) { int8 i,sec,min,hour,day,date,month,year; // ก������1��� F�0��1�;" 8 �0� (0-256) �nt16 tpx,all_tp; // ก������1��� F�0��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);

Page 16: Rtc simulator with proteus

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"); } }