background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Программирование МК PIC. Урок 4. Кнопка"

input logo icon
Table of contents
|

Table of contents

0:00
Введение
1:40
Преобразуем прошлый проект в новый без потери кода
4:44
Подключим кнопку в протеусе
7:04
Напишем функцию отслеживания состояния кнопки, в которой также проведём борьбу с дребезгом
10:30
Отследим нажатие кнопки в бесконечном цикле
12:10
Проверим работу кода в протеусе
12:40
Проверим работу кода на практической схеме.
Video tags
|

Video tags

Микроконтроллеры PIC
Кнопка
PIC
МК PIC
MPLAB X IDE
MPLAB XC8
Программирование МК
Программирование PIC
PIC16F84A
Программирование СИ
Программирование микроконтроллеров
Программирование
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:01
[music]
00:00:02
hello everyone, dear friends, today we
00:00:05
continue to
00:00:06
program microcontrollers pic we still have
00:00:08
peak 16 f 84,
00:00:13
well, we can say at the moment it is the
00:00:15
simplest, but it is convenient to
00:00:17
start with since it has a
00:00:21
smaller datasheet and is harder to get confused that is, if
00:00:24
you, for example, take some
00:00:27
877 peak and run the same project, but
00:00:30
not necessarily the same one, you create a new one
00:00:32
but use the same code, then the code
00:00:35
will work successfully on those
00:00:37
controllers, that is, what is good about the peak, it is
00:00:40
backward compatible,
00:00:42
but although if in the average family this would be true,
00:00:45
that is, for example, timer 0 or there are
00:00:48
some other registers that 84 already has,
00:00:51
877 definitely has it, and then
00:00:55
new registers could appear, but these
00:00:57
will definitely be there, that is, these are
00:00:59
very convenient, that is, I this I checked
00:01:02
it all works great, you can
00:01:04
easily choose a board from your ball with 877
00:01:09
and work with my lessons safely, well, that’s
00:01:12
okay today we have a continuation so far
00:01:15
working with ports,
00:01:17
we already worked with them in the last lesson
00:01:20
successfully on the output
00:01:23
by using them and controlling them on the output
00:01:26
Today we’ll try to use the
00:01:29
input port school and track the level at this input
00:01:32
and, for example, connect a
00:01:36
button there with this button to control something,
00:01:39
so we’ll name our project
00:01:42
accordingly, let’s call mine bottom 0 1st
00:01:46
place blink and now I’ll teach you how to make a
00:01:48
project out of a previous project another, that
00:01:52
is, without losing the code, we can do this
00:01:55
already on vr on stm, it’s peak I haven’t
00:01:59
shown it yet, create a folder, here’s the loaf 0 1
00:02:03
x copy everything from our code in the
00:02:07
last lesson, not everything, but you can take
00:02:10
this file resisted the main mix file and the
00:02:14
nb project folder, accordingly,
00:02:18
we rename the file with the prosthesis, of
00:02:21
course we don’t touch anything here, we go into the
00:02:24
India project folder, we leave there only
00:02:26
these two configurations files of its
00:02:30
project, we delete everything else, we
00:02:31
go into the project xml and we change
00:02:36
only this x in it, we remove it and that’s it
00:02:41
blink 01 to loaf 01, that’s it, we save everything
00:02:45
and our project is basically ready, we can
00:02:48
safely go to VMP Lap and connect it,
00:02:52
that is, this is how we created a new
00:02:54
project without losing the codes of the old project,
00:02:57
or on this button we press open
00:03:00
project or file open project,
00:03:03
respectively in the folder with our
00:03:05
projects, select the corresponding
00:03:08
project
00:03:09
bottom 01 with the right button, call up the
00:03:13
context menu in the tree of
00:03:15
our project and put it in the main set
00:03:20
with my project, we open beyonce in it
00:03:24
and try to assemble it, press f11,
00:03:28
but everything is assembled as you see
00:03:31
loaf 0 1 x production hex
00:03:34
we created perfectly, what needs to be done to
00:03:38
assign a
00:03:39
port pin to the output is clear to do since when
00:03:45
we assigned it, that is, to the input,
00:03:47
once we assigned it to the output,
00:03:50
we set the corresponding bit of this
00:03:52
pin to one, then it’s clear that we
00:03:54
need to set it to zero in the
00:03:59
fig register of the corresponding the letter of the port,
00:04:02
so well, you
00:04:07
can try to assemble the project again, you ca
00:04:10
n’t try it, it wo
00:04:12
n’t go anywhere, it will assemble, let’s first
00:04:15
take a
00:04:16
little break from where and work a little with the
00:04:20
opposite ourselves, we’ll connect a button there, that is,
00:04:22
we connect the button with you, as we
00:04:26
understood from if there is a 4 here, it means
00:04:29
2 bit is not 0 not 1 2 that is, from the right we
00:04:34
are moving 2 0 will be to the right 3 1
00:04:37
if you imagine what 4 is in
00:04:39
hexadecimal then 100 in binary in
00:04:42
binary calculus y add a button I
00:04:46
think the button we all know how to add
00:04:49
forced we type here the loaf and the button
00:04:55
ours
00:04:56
will be connected, let's first
00:05:03
probably move a little here
00:05:07
so it will be easier, well, let's
00:05:13
connect it like this, and I can do everything with a common wire like this, so
00:05:21
copy here, let's connect like this with a
00:05:24
common wire, and because we have
00:05:29
ports with you and
00:05:30
open collector of their legs, then it is best to
00:05:33
tighten it with some kind of
00:05:35
resistor because power wires, that is,
00:05:40
we find the power wire, more go,
00:05:51
the resistor was already with you, so it
00:05:53
will be easier for us and this is exactly
00:06:00
what we need a 10 kilohm press in
00:06:03
the most normal way, I also connected it,
00:06:06
as you remember, if you watched my
00:06:08
classes on the era then this resistor
00:06:11
could be tightened programmatically, they say, the
00:06:13
peak also has software
00:06:16
support for resistor registers, sorry,
00:06:18
but it’s not quite so simple, the hatch of
00:06:23
any leg is difficult, the resistor
00:06:26
can be tightened, you can
00:06:28
pull up the resistors with port B, there is a special
00:06:32
register there for this, but it’s better to
00:06:35
use a real resistor At the
00:06:38
same time, let's go to the property of
00:06:40
the controller and show our project
00:06:45
because I'm showing it to you because
00:06:48
I've already done all this and that's why he
00:06:50
remembers, that is, we need to show him our
00:06:53
current firmware, I hope you
00:06:56
know how to do this, but let's say for now what kind of
00:06:58
cat there is, let's say you and I have
00:07:01
LEDs running well, now let's go to the project
00:07:05
and let's add a function here to
00:07:07
determine whether a button is pressed or not pressed
00:07:11
a function that at first glance seems
00:07:13
not entirely easy, in fact it is very
00:07:17
easy to know what we do here when
00:07:20
entering a function we have no there
00:07:22
will be no parameters since we are not
00:07:25
setting something, but on the contrary we are getting it, that
00:07:27
is, on the contrary, we
00:07:29
will have an 8-bit unsigned response
00:07:34
from the function, that is, the returned parameter
00:07:36
will be therefore we create similar
00:07:39
variables locally and
00:07:41
resort also another variable for
00:07:43
counting and now you will understand why we can
00:07:45
count and go into such a cycle
00:07:48
that will determine whether
00:07:51
our leg is pressed,
00:07:52
but since we need to track the low
00:07:54
level, it is always a high level and the
00:07:57
mouse is pulled up to a high button pressed,
00:07:59
on the contrary, we will have the leg so
00:08:01
low level
00:08:03
when pressing connect, so we
00:08:06
monitor the low level on these legs,
00:08:09
that is, we check the bit
00:08:12
for zero, so this is how we do
00:08:16
ra2! we put it, that is, we have a negation,
00:08:21
that is, a low level, so to speak, and
00:08:24
if we have this bit to it is not equal to
00:08:27
ten thousand,
00:08:28
then we increase it, then we no longer
00:08:32
fall into this wells condition in this body,
00:08:35
since we still have
00:08:38
less
00:08:39
again, or do the next iteration,
00:08:41
run through the body of our loop
00:08:44
and until we reach 10,000,
00:08:47
then here in thousands we get 10
00:08:49
milliseconds, somewhere around 20, you can
00:08:52
check all this, as I showed you,
00:08:54
there is an excellent tool called
00:08:58
stopwatch feet or stopwatch that is,
00:09:02
you can use it, it can all be
00:09:05
selected experimentally, why do
00:09:08
we need it, we need it in order to
00:09:11
combat chattering at the same time,
00:09:14
that is, a short
00:09:18
circuit to the buttons may accidentally occur, but not a short circuit, the
00:09:20
connection of the contacts, but as a rule, it’s
00:09:23
accidental, but sometimes it’s not necessary,
00:09:24
but 10 milliseconds, I think we can easily
00:09:29
hold the button, that is, when we
00:09:31
press it, if we press it very briefly,
00:09:33
it will not work the code, that is, now
00:09:35
we have reached 10 thousand, that is,
00:09:38
we already have no less than a baht count of 10 thousand,
00:09:41
then we find ourselves in this is the cycle, that
00:09:45
is, in this condition we
00:09:47
set the result to one and we
00:09:50
exit this cycle, we
00:09:53
get here and return the resort if
00:09:55
suddenly we do not reach this value and
00:09:59
find that here the
00:10:01
level we need is low will disappear, then we
00:10:05
will exit this loop but the result
00:10:08
variable will remain zero, that
00:10:10
is, by doing so, we define the check
00:10:13
as if it is a loaf or nothing, that is, whether
00:10:16
it is pressed or not, that is, that is,
00:10:18
in a very convenient function, you
00:10:20
can try to place a thousand, I
00:10:23
even did earlier up to 5 I thought it
00:10:25
worked quite well, that is, this is how
00:10:26
contact bounce tracking works, but
00:10:29
all we have to do is call
00:10:32
the function given somewhere with you, you can call it here, here, that is,
00:10:37
we are here with you,
00:10:39
if you remember from the last lesson,
00:10:41
the mileage is happening lit
00:10:44
LEDs, that is, a running fire, and
00:10:48
here we will insert the data with you,
00:10:53
in general, this entire cycle will run
00:10:55
so much only when we discover
00:10:57
here that we have
00:10:58
a button pressed, if our button is not
00:11:04
pressed, then no we
00:11:07
don’t get into this cycle, that is, the kit, without any
00:11:10
delays, constantly monitors here to see if
00:11:13
the button is pressed, this is our
00:11:15
infinite loop, if it’s pressed
00:11:17
suddenly there and we get here, even if we press the
00:11:20
button while working, this is the
00:11:24
code, then the code before works until end, well,
00:11:28
there is some problem here, we
00:11:30
will see it with you now, let’s not localize it
00:11:33
with you for now, so to speak, look,
00:11:36
we launch accordingly,
00:11:39
nothing is running now, we press the button,
00:11:41
the fire started running and it didn’t go out for us in the
00:11:44
end here than the chip, that is,
00:11:47
we will remove this chip with you, that is, we
00:11:49
will take this from here with you to the clipboard,
00:11:52
we will delete the data center and we will dry it, the
00:11:56
LED data connected through a
00:12:00
current-limiting resistor. and ra2 is
00:12:03
right here after the delay that’s all and
00:12:06
we’ll have everything work fine with you then
00:12:08
let’s try again,
00:12:12
assemble, launch, press, it
00:12:17
ran and went out, that is, and just like that, we
00:12:19
can, as we remember,
00:12:22
lock the button if we
00:12:24
always have it with a knife this will be the
00:12:27
running lights and that's it, this is how we
00:12:31
got the code, that is, today we
00:12:33
learned how
00:12:35
to track the level on the port leg,
00:12:38
well, let's of course look at all this
00:12:42
on the real diagram,
00:12:44
let's run with you the programs for
00:12:47
flashing since you have a programmer with
00:12:50
us we agreed with you that it’s not
00:12:54
branded, it’s not a third party, he doesn’t
00:12:57
know ours, he wanted to say our studio, this is what
00:13:00
happens, so to speak, an
00:13:04
option when we haven’t yet connected
00:13:06
the programmer, we launched
00:13:08
this thing, that is, we won’t disable this
00:13:10
program
00:13:11
close and now let’s connect
00:13:14
our controller,
00:13:17
connect it and do this, check
00:13:22
communications and most likely we
00:13:25
will have our controller, but it wasn’t found,
00:13:28
apparently I may be here, but I did
00:13:30
n’t connect it quite correctly;
00:13:36
and we found everything under
00:13:42
control, let’s turn it down a little here with
00:13:45
the key and here we have a tiny little one
00:13:49
running, but these are some lights of this one, and then it
00:13:52
tries to trust and the lights run according to a
00:13:54
timer, so wait for a lesson, that
00:13:57
is, the code and the timer are mixed here not a
00:14:02
timer, that is, and in an endless loop, I will
00:14:04
now press a button and there will be another
00:14:06
light before occupying that quadruples he will
00:14:08
lag behind will see that in the
00:14:12
timer procedure in the
00:14:14
interrupt handler the fire is running and the fact that I
00:14:17
press the button, that is, what I am
00:14:21
showing is that the processing procedure of
00:14:23
the timer does not depend in any way on the main
00:14:25
code, it does not interfere with its work,
00:14:28
that’s the thing, well, the button is like this, I
00:14:31
connected it to the phone, you can see it just
00:14:34
with the legs first, the usual clock
00:14:36
button is here, I stuck it in, but it
00:14:41
often popped out, so I soldered it to it
00:14:45
These are the usual pins I took from the
00:14:48
pin strip and now she
00:14:51
feels very confident here, so to speak,
00:14:55
and plus, of course, we see the button where we
00:14:58
connect from, we connect and Minvod from the
00:15:00
very first contact with you, let’s
00:15:07
open the datasheet or something and peak 84
00:15:12
hey document here we are We’ll see that this is
00:15:16
ra2, which is great, and it goes to the button here,
00:15:21
and the second contact button is this
00:15:24
part, it goes to the common wire, to the
00:15:27
minus wire, to the blue stripe, and we have a
00:15:30
10 kilo-ohm resistor like this, some
00:15:32
old one, I found, well, it works fine
00:15:35
you have already noticed that this is of course a
00:15:38
different project, but I just
00:15:40
delighted you in advance before the
00:15:43
next lessons, I usually keep it a secret,
00:15:47
well, I don’t see the point in it now, well, of course, I
00:15:52
already tried it here, but it’s better
00:15:54
let’s open it as expected, here
00:15:56
we are blink and we need bottom
00:15:59
01 go to gist default production then 0
00:16:04
1 x we ​​all have configuration
00:16:07
bits and we are flashing our controller,
00:16:11
all the controller is flashed we see that
00:16:13
no lights are running, we press the
00:16:16
button they ran very
00:16:18
briefly press they did not run,
00:16:20
that is, like this fight against rattling,
00:16:22
that is, we turned it down and it will work for a short time,
00:16:25
work will work,
00:16:28
we press normally, that is, they ran, so the
00:16:30
number is 10,000 where you can pick it yourself,
00:16:34
I hope this is what we
00:16:37
got today, a short but quite
00:16:40
informative lesson we learned from you can
00:16:43
monitor the status of the input port, we have
00:16:46
connected a button to the input and now we
00:16:48
can quite control something, that is, we can
00:16:50
connect several buttons and so on,
00:16:54
thank you all for your attention, wait for the
00:16:56
next lessons, that is, the next lesson
00:16:59
we will most likely have on a timer,
00:17:01
that is, while we are working specifically with the
00:17:04
eighty-fourth controller, but
00:17:06
most likely after the fifth lesson on the
00:17:08
timer we will switch to the 876 controller
00:17:13
which has a slightly larger knife and there
00:17:16
will be more of these different timers, we
00:17:18
will work with other timers, they can
00:17:21
already be used in shim mode, then a
00:17:25
sold-out party
00:17:27
at the sart awaits us As usual, you will be working with a
00:17:30
static indication using a
00:17:33
seven-segment indicator, also with a
00:17:36
dynamic indication using
00:17:38
several or a bass
00:17:40
1 indicator leg of a bit, well, as a
00:17:43
rule, 4 so wait, it will be interesting,
00:17:46
that is, I have all this in the stm burst,
00:17:49
you see, of course, but the peak is a little
00:17:51
it’s all different, that is, so we’ll
00:17:54
look and peak I won’t really
00:17:57
explain the intricacies of C programming, I
00:18:01
hope you know this, if you don’t know then
00:18:04
look at the lessons there, I explain
00:18:08
what such a function is, how it calls how
00:18:11
it returns what parameters
00:18:13
then there is how it accepts them, what are while
00:18:16
loops, what is an infinite loop, a
00:18:18
finite loop, a for loop, so if you need
00:18:22
to look there, well, or some
00:18:25
kind of reference books or
00:18:26
lessons, you use it again,
00:18:29
thank you all for your attention, write comments
00:18:32
with press the button, I like it if you
00:18:34
liked this video about leaving the age of
00:18:36
what lesson you will immediately learn if
00:18:39
you subscribe to the channel and turn on
00:18:42
the notification to everyone, bye everyone
00:18:45
good health

Description:

Сегодня мы продолжим работу по программированию контроллеров PIC. На данном уроке мы по прежнему работаем с контроллером PIC16F84A и подключим к нему ещё кнопку. Цель подключения кнопки - поработать с ножками порта в режиме их настройки на вход. Мы также испытаем затем наш код и в протеусе и на практической схеме. Приобрести программатор PICKit3 (неоригинальный) можно здесь http://ali.pub/24fd8t Приобрести программатор PICKit3 (оригинальный) можно здесь http://ali.pub/24fdzu Навигация по видео: 00:00 Введение 01:40 Преобразуем прошлый проект в новый без потери кода 04:44 Подключим кнопку в протеусе 07:04 Напишем функцию отслеживания состояния кнопки, в которой также проведём борьбу с дребезгом 10:30 Отследим нажатие кнопки в бесконечном цикле 12:10 Проверим работу кода в протеусе 12:40 Проверим работу кода на практической схеме. Для более понятного просмотра данного видео предварительно рекомендуется посмотреть: Урок 1. Знакомство с семейством PIC https://www.youtube.com/watch?v=Ut9j4JINpSw Урок 2. Первый проект в MPLAB X IDE https://www.youtube.com/watch?v=P4CKlUionBo Текстовая версия урока и исходный код здесь https://narodstream.ru/pic-urok-4-knopka/ Группа в контакте http://vk.com/club116656325 Группа в Одноклассниках http://ok.ru/group/52987126153436 Группа в Facebook https://www.facebook.com/unsupportedbrowser Мой сайт "Программирование МК" https://narodstream.ru/ Форум https://narodstream.ru/forum/ Вы можете помочь проекту: ЮMoney https://yoomoney.ru/to/41001176473465 Webmoney Z341906933112 Карта Сбербанка (МИР) 2202201799288929 Можно в USDT 1) Сеть:TRC20 Адрес: TBBPFk5Widf1CYvF7Xk5ssKXeiPJHwtMgS 2) Сеть: BSC BNB Smart Chain (BEP20) (комиссия намного меньше) Адрес: 0x2e38754DF1e54649Bf0D5CD6fD6D8c96a9f22f17 3) Сеть: Huobi ECO Chain (HECO) (комиссия еще меньше) Адрес: 0x2e38754DF1e54649Bf0D5CD6fD6D8c96a9f22f17

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Программирование МК PIC. Урок 4. Кнопка" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Программирование МК PIC. Урок 4. Кнопка" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Программирование МК PIC. Урок 4. Кнопка" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Программирование МК PIC. Урок 4. Кнопка" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Программирование МК PIC. Урок 4. Кнопка"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Программирование МК PIC. Урок 4. Кнопка"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.