Jump to content

Welcome to vip-cxema.org

logo3.png

The forum has a section for guests, where you can ask your questions without registration: Вопросы и ответы

By registering, you will be able to send private messages, receive notification of replies to topics. You can always send a message, many restrictions are removed.


Evgeniy

Урок 8_1 добавляем кнопки

Recommended Posts

Так как у pic16f84 недостаточно выводов, меняем его на pic16f628A, переводим его на работу от внутреннего генератора.

8.JPG

 

Код:

 

@ device pic16f628a, cpd_off, protect_off, mclr_off, pwrt_on, wdt_off, INTRC_OSC_NOCLKOUT
'*******************************************************************************
trisA = %11110000
trisB = %00000000
'*******************************************************************************
LED var portB
ind1 var portA.0
ind2 var portA.1
ind3 var portA.2
ind4 var portA.3
Plus var portA.7 'Кнопка +
Minus var portA.6 'Кнопка -
Res var portA.5 'Кнопка сброса
Temp var word
i var byte
n var byte
buf1 var byte
buf2 var byte
buf3 var byte
'*******************************************************************************
clear
led = 0
ind1 = 1
ind2 = 1
ind3 = 1
ind4 = 1
temp = 100
'*******************************************************************************


'*******************************************************************************
main:
button plus, 0,255,255,buf1,1,TPlus
button minus,0,255,255,buf2,1,TMinus
button res, 0,255,255,buf3,1,TReset
gosub display
goto main
'*******************************************************************************


'*******************************************************************************
TPlus:
temp = temp + 1
if temp > 9999 then temp = 0
goto main
'*******************************************************************************


'*******************************************************************************
TMinus:
temp = temp - 1
if temp > 10000 then temp = 9999
goto main
'*******************************************************************************


'*******************************************************************************
TReset:
temp = 0
goto main
'*******************************************************************************


'******************************* Индикация *************************************
Display:
for i = 0 to 3
n = temp dig i
ind1 = 1
ind2 = 1
ind3 = 1
ind4 = 1
Lookup n,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],led
if i = 0 then
ind1 = 1
ind2 = 1
ind3 = 1
ind4 = 0
endif
if i = 1 then
ind1 = 1
ind2 = 1
ind3 = 0
ind4 = 1
endif
if i = 2 then
ind1 = 1
ind2 = 0
ind3 = 1
ind4 = 1
endif
if i = 3 then
ind1 = 0
ind2 = 1
ind3 = 1
ind4 = 1
endif
pauseus 500
next i
return
'*******************************************************************************

 

8_1.rar

Share this post


Link to post
Share on other sites
 
 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...



×
  • Create New...