внутреннего кварца нет!!!
там RC генератор
roboforum.ruТехнический форум по робототехнике. |
|
|
OCR1A = 31250
TCCR1A = 0
TCCR1B = (1<<WGM12)|(1<<CS12)
$regfile = "m16def.dat" ' specify the used micro
$crystal = 8000000
$lib "lcd4.lib"
'*** Config the timer ***
Config Timer1 = Timer , Prescale = 256 , Clear Timer = 1
' Load the TimerLimit value into the Compare1A (OCR1A) register
Compare1a = 31250
' Set interrupt pointers
On Timer1 Int_1
' When Timer1 moves from 65535 to 0 - not just when it becomes 0
' as Timer1 moves between 0 and 10000, the Timer1 interrupt flag is never set.
On Compare1A Compare_1a_int
' Wwhen Timer1 = Compare1A register
' Enable the use of Timer1
Enable Compare1a
Enable Interrupts
'**************END config Timer**************
Config Lcdpin = Pin , Rs = Porta.0 , E = Porta.2 , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7
Config Lcd = 16 * 2
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim H1 As Integer
Dim H2 As Integer
Dim M1 As Integer
Dim M2 As Integer
Dim S1 As Integer
Dim S2 As Integer
Gosub Clockzero
Locate 2 , 1
Lcd "Hour:"
Locate 2 , 8
Lcd "Min:"
Locate 2 , 13
Lcd "Sec:"
Do
Locate 1 , 13
Lcd S1
Locate 1 , 14
Lcd S2
Locate 1 , 8
Lcd M1
Locate 1 , 9
Lcd M2
Locate 1 , 1
Lcd H1
Locate 1 , 2
Lcd H2
Loop
Int_1:
'empty
Return
Compare_1a_int:
' Reset the Compare1A interrupt flag,
' as this flag is not reset automatically
Reset Tifr.5
S2 = S2 + 1
If S2 = 10 Then S1 = S1 + 1
If S2 = 10 Then S2 = 0
If S1 = 6 Then M2 = M2 + 1
If S1 = 6 Then S1 = 0
If M2 = 10 Then M1 = M1 + 1
If M2 = 10 Then M2 = 0
If M1 = 6 Then H2 = H2 + 1
If M1 = 6 Then M1 = 0
If H2 = 10 Then H1 = H1 + 1
If H2 = 10 Then H2 = 0
If H1 = 2 And H2 = 4 Then Gosub Clockzero
Return
Clockzero:
Let S1 = 0
Let S2 = 0
Let H1 = 0
Let H2 = 0
Let M1 = 0
Let M2 = 0
Let M1 = 0
Let M2 = 0
Return
CONFIG CLOCK
'-----------------------------------------------------------------------------------------
'name : megaclock.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : shows the new TIME$ and DATE$ reserved variables
'micro : Mega103
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
$regfile = "m103def.dat" ' specify the used micro
$crystal = 4000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
'With the 8535 and timer2 or the Mega103 and TIMER0 you can
'easily implement a clock by attaching a 32768 Hz xtal to the timer
'And of course some BASCOM code
'This example is written for the STK300 with M103
Enable Interrupts
'[configure LCD]
$lcd = &HC000 'address for E and RS
$lcdrs = &H8000 'address for only E
Config Lcd = 20 * 4 'nice display from bg micro
Config Lcdbus = 4 'we run it in bus mode and I hooked up only db4-db7
Config Lcdmode = Bus 'tell about the bus mode
'[now init the clock]
Config Date = Mdy , Separator = / ' ANSI-Format
Config Clock = Soft 'this is how simple it is
'The above statement will bind in an ISR so you can not use the TIMER anymore!
'For the M103 in this case it means that TIMER0 can not be used by the user anymore
'assign the date to the reserved date$
'The format is MM/DD/YY
Date$ = "11/11/00"
'assign the time, format in hh:mm:ss military format(24 hours)
'You may not use 1:2:3 !! adding support for this would mean overhead
'But of course you can alter the library routines used
Time$ = "02:20:00"
'---------------------------------------------------
'clear the LCD display
Cls
Do
Home 'cursor home
Lcd Date$ ; " " ; Time$ 'show the date and time
Loop
'The clock routine does use the following internal variables:
'_day , _month, _year , _sec, _hour, _min
'These are all bytes. You can assign or use them directly
_day = 1
'For the _year variable only the year is stored, not the century
End
а сам МК будет работать от внутреннего тактирования...
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1