Moderators: stojke369, pedja089, [eDo], trax
DEFINE LCD_BITS 4
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_LINES 2
pause 500
COUNTER VAR BYTE
SECOND VAR BYTE
start:
OPTION_REG = %00110010
INTCON = %00100100
On Interrupt GOTO BROJAJNE
BROJAJNE:
COUNTER = COUNTER + 1
IF COUNTER > 32 THEN SECOND = SECOND + 1
LCDOUT $FE,1,DEC SECOND
INTCON = 0
TMR0 = 0
RESUME
GOTO START'**************************************************************** *
'* Notes : To use this example with MicroCode Studio, you *
'* : should: *
'* : (1) Compile this code and program your target *
'* : MCU using the 'Compile and Program' button *
'* : or F10 *
'* : (2) Ensure that a serial cable is connected to *
'* : your PC and development board (using a *
'* : suitable line driver like a MAX232) *
'* : (3) Open the Serial Communications Window (from *
'* : VIEW or just press F4 *
'* : (4) Select the correct COM port and set the *
'* : baudrate to 19200 *
'* : (5) Press the 'Connect' button *
'****************************************************************
'define LOADER_USED 1 ' using a loader, OK to leave in if a loader is not used
define OSC 20 ' this example uses a 20MHz clock
DEFINE HSER_BAUD 19200 ' set baud rate to 19200
Minute var byte ' Define minute variable
Second var byte ' Define second variable
Ticks var byte ' Define pieces of seconds variable
DoUpdate var byte ' Define variable to indicate update
clear ' clear all RAM (sets all VAR declarations to zero)
DoUpdate = 1 ' Force first display
OPTION_REG = $57 ' Set TMR0 configuration
INTCON = $A0 ' Enable TMR0 interrupts
On Interrupt Goto TickInterrupt
' Main program loop
MainLoop:
if DoUpdate then
hserout [dec2 Minute,":", dec2 Second,$D,$A]
DoUpdate = 0
endif
Goto MainLoop
' Interrupt routine to handle each timer tick
' Disable interrupts during interrupt handler
disable
TickInterrupt:
Ticks = Ticks + 1 ' Count pieces of seconds
If Ticks < 61 Then ExitInterrupt ' 61 ticks per second
' One second elasped - update time
Ticks = 0
Second = Second + 1
If Second >= 60 Then
Second = 0
Minute = Minute + 1
If Minute >= 60 Then
Minute = 0
endif
Endif
DoUpdate = 1 ' Set update
ExitInterrupt:
INTCON.2 = 0 ' Reset timer interrupt flag
Resume'****************************************************************
'* Name : dimer.BAS *
'* Author : [niho] *
'* Notice : Copyright (c) 2010 [niho] *
'* : All Rights Reserved *
'* Date : 16.01.2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
@ DEVICE pic16f84a,XT_OSC,WDT_OFF,PROTECT_OFF 'definicija konfiguracije
DEFINE OSC 4 'definicija oscilatora
i VAR BYTE 'postavka prvog brojaca (varijable)
i=1
SYMBOL LED=portb.7 'postavka simbola zamjene pinova
SYMBOL taster1=portb.0
symbol taster2=portb.1
OUTPUT LED
INPUT TASTER1 'postavke ulaza-pojacavanje int.svjetla
input taster2 'smanjivanje intenziteta svjetla
pocetak: 'radni potprogram
low led
pause i
high led
pause 30-i
if taster1=0 then i=i+1 'pojacavanje svjetla
if taster2=0 then i=i-1 'smanjivanje svjetla
if i>30 then i=30 'ogranicenje pauze
if i<1 then i=1
goto pocetak
end ' kraj :1000000028288F018E00FF308E07031C8F07031CEA
:10001000232803308D00DF300F2003288D01E83EB8
:100020008C008D09FC30031C18288C070318152838
:100030008C0764008D0F15280C181E288C1C222894
:1000400000002228080083130313831264000800B1
:100050000130A600831686130614861483128613B5
:1000600083168613831226080120861783168613AB
:10007000831226081E3C9E000030031CFF3E9F009A
:100080001F088F001E080220640006184828A60AD0
:10009000640086184C28A60364001F302602031C47
:1000A00053281E30A60064000130260203185A2887
:0A00B0000130A6002F2863005B2832
:02400E00F13F80
define osc 10
DEFINE LCD_BITS 4
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_LINES 2
pause 500
pwmr var word
pwmr = 0
pwmrw var word
start:
if portb.2 = 1 then
pwmr = pwmr + 1
pause 80
endif
pwm portb.4,pwmr,1
pwmrw = pwmr
lcdout $fe,1,"Razina:",dec2 pwmrw,"%"
goto startReturn to Mikrokontroleri - PIC
Users browsing this forum: No registered users and 1 guest