Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
RTC selection

RTC selection

Ratings:

5.0

(1)
|Views: 139 |Likes:
Published by madhuvariar

More info:

Published by: madhuvariar on Aug 09, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/07/2010

pdf

text

original

 
App1App1App1App1App11818181818Read/WRead/WRead/WRead/WRead/Write Trite Trite Trite Trite Time Time Time Time Time To DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chip
 © 1999-2002 Basic Micro.com ® All Rights Reserved No portion of this work may bereproduced without prior written consent from Basic Micro Inc.
IntroductionIntroductionIntroductionIntroductionIntroduction
MBASIC PROGRAM TO READ/WRITE TIME TO THE DALLAS DS1302 RTC CHIP, DISPLAYS TIME INBCD USING 4 COLUMNS OF LED’S. INTERRUPT ROUTINE MULTIPLEXES THE TIME TO THEDISPLAY USES PORTA BITS 0-2 TO TALK TO THE DS1302. BITS 3-4 FOR SETTING THE TIMEUSES PORTB BITS 0-3 FOR NUMBER TO OUTPUT, AND BITS 4-7 TO TURN ON TRANSISTORSSECONDVARBYTEMINUTEVARBYTEHOURVARBYTEDATEVARBYTEMONTHVARBYTEDAYVARBYTEYEARVARBYTETEMPVARBYTEDIGITVARBYTE;LOOP COUNTER TO SERVICE ONE DIGIT AT A TIMEDIGVARBYTE(4);DIGIT PLACEHOLDERSTRANSVARBYTE(4);TRANSISTOR MASK FOR DISPLAY, 0 TURNS ON DISPLAYHRBTNVARBYTE;WORKSPACE FOR HOUR BUTTONMINBTNVARBYTE;WORKSPACE FOR MINUTE BUTTONMINSETCONA3HRSETCONA4CSCONA0;RST OR CHIP SELECT LINESDATACONA1;DATA I/O LINESCLKCONA2;CLOCK LINETRANS(0) = %11101111;MASK FOR 1ST DIGITTRANS(1) = %11011111;MASK FOR 2ND DIGITTRANS(2) = %10111111;MASK FOR 3RD DIGITTRANS(3) = %01111111;MASK FOR 4TH DIGITONINTERRUPT TMR0INT,CLOCK;SET UP TIMER 0 INTERRUPT ROUTINESETTMR0 TMR0INT32;TO MULTIPLEX THE DISPLAYSENABLE TMR0INT;REQUIRES LEAST AMOUNT OF WORK TO USE AND IS;FAST ENOUGH;CONFIGURE I/OTRISA = %11111000;PORTA BITS 0-2 OUTPUT, 3-7 INPUTPORTA = %00000000;TURN OFF ALL OUTPUTSTRISB = %00000000;PORT B ALL OUTPUTSPORTB = %00001111;TURN OFF ALL LEDSCMCON = %00000111;TURN OFF COMPARATORS;INITIALIZE SOME VALUES
 
App1App1App1App1App11818181818Read/WRead/WRead/WRead/WRead/Write Trite Trite Trite Trite Time Time Time Time Time To DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chip
 © 1999-2002 Basic Micro.com ® All Rights Reserved No portion of this work may bereproduced without prior written consent from Basic Micro Inc.
MAINGOSUB CLKINIT;INITIALIZE CLOCK TO 12:00 AM; 1/1/02; DAY 1; 12;HR ;ENABLED;SET TIME VALUES HERE TO WRITE TO CLOCK WITH;ANYTHINGSECOND = $30;DIFFERENT THAN DEFAULTMINUTE = $59HOUR = $12DATE = $07MONTH = $03DAY = $04YEAR = $02HOUR = HOUR | $80;SET TO 12 HR FORMAT;SET TIME VALUES HERE TO WRITE TO CLOCK GOSUB WRITETIME;WRITE NEW TIME VALUES TO CLOCKRDLOOPGOSUB READTIME;READ THE TIME INBUTTON MINSET,1,3,2,MINBTN,1,SETMIN;CHECK TO SEE IF MINUTE SET BUTTON IS PRESSEDBUTTON HRSET,1,5,2,HRBTN,1,SETHR;CHECK TO SEE IF HOUR SET BUTTON IS PRESSEDFOR TEMP = 1 TO 255;JUST A DELAY LOOPTEMP = TEMP NEXTGOTO RDLOOP;LOOP FOREVESETMINTEMP = (BCD2BIN MINUTE);CONVERT MINUTE TO BINARYTEMP = TEMP + 1;ADD 1 TO THE MINUTEIF TEMP > 59 THEN;CHECK TO SEE IF OVER 59TEMP = 0;IF IT IS RESET TO ZERO - HOUR COULD BE ADDED;HEREENDIFMINUTE = (BIN2BCD TEMP);CONVERT BACK TO BCDGOSUB WRITETIME;GO WRITE NEW TIMEGOTO RDLOOP;RETURN TO MAIN LOOPSETHR HOUR = HOUR & %00011111;MASK OFF FORMAT AND AMPM INDICATOTEMP = (BCD2BIN HOUR);CONVERT HOUR TO BINARYTEMP = TEMP + 1;ADD 1 TO THE HOUIF TEMP > 12 THEN;IF HOUR > 12 THEN RESET TO 1TEMP = 1;IF 24 HOUR FORMAT IS USED, DO NOT MASK AND;COMPARE TO 24ENDIFHOUR = (BIN2BCD TEMP);CONVERT HOUR BACK TO BCD
 
App1App1App1App1App11818181818Read/WRead/WRead/WRead/WRead/Write Trite Trite Trite Trite Time Time Time Time Time To DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chipo DS1302 RTC Chip
 © 1999-2002 Basic Micro.com ® All Rights Reserved No portion of this work may bereproduced without prior written consent from Basic Micro Inc.
GOSUB WRITETIME;GO WRITE NEW TIMEGOTO RDLOOP;RETURN TO MAIN LOOPCLKINITLOW SCLK;MAKE SURE CLOCK LINE STARTS LOWIF USING BATTERY BACKUP WITH DS1302, USE THIS ROUTINE INSTEAD OF INITIALIZING THE TIMEAND DATE TO A FIXED VALUE - READS CURRENT TIME FROM DS1302 INTO PICHIGH CS;SELECT DS1302SHIFTOUT SDATA,SCLK,LSBPRE,[$87\8,$00\8];ENABLE WRITE PROTECTLOW CS;DESELECT DS1302GOSUB READTIME;READ TIME FROM DS1302RETURN;RETURN TO MAIN LOOPTHE FOLLOWING CODE WOULD BE REPLACED IF USING BATTERY TO KEEP TIME IN DS1302HIGH CS;SELECT DS1302SHIFTOUT SDATA,SCLK,LSBPRE,[$BE\8,$00\8,$00\8];BURST WRITE, SECONDS &;MINUTES TO 0SHIFTOUT SDATA,SCLK,LSBPRE,[$92\8];HOUR TO 12 AM, 12 HOU;FORMATSHIFTOUT SDATA,SCLK,LSBPRE,[$01\8,$01\8];DATE TO 1, MONTH TO 1SHIFTOUT SDATA,SCLK,LSBPRE,[$01,$02\8];DAY TO 1, YEAR TO 02SHIFTOUT SDATA,SCLK,LSBPRE,[$00\8];CONTROL REGISTER TO 0LOW;CS;DESELECT DS1302RETURNWRITETIMEHOUR = HOUR | $80;KEEP IN 12 HR FORMATHIGH CS;SELECT DS1302SHIFTOUT SDATA,SCLK,LSBPRE,[$BE\8,SECOND\8,MINUTE\8,HOUR\8];COMMAND TO;BURST WRITESHIFTOUT SDATA,SCLK,LSBPRE,[DATE\8,MONTH\8,DAY\8,YEAR\8,$00\8];MUST WRITE ALL 8;BYTESLOW CS;DESELECT CHIPRETURNREADTIMEHIGH CS;SELECT DS1302SHIFTOUT SDATA,SCLK,LSBPRE,[$BF\8];COMMAND TO BURST READSHIFTIN SDATA,SCLK,LSBPOST,[SECOND\8,MINUTE\8,HOUR\8];BURST READ;CLOCK 

Activity (3)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
tuyen1989 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->