avr計數_使用8位LCD創建計數器| AVR

avr計數

This type of counter may be also used in the EVM machines. A counter can be used to count the number of times a button is pressed. It can have many applications. The most widely used counter application is in EVM and also in customer feedback machines.

這種類型的計數器也可以在EVM機器中使用。 計數器可用于計算按下按鈕的次數。 它可以有很多應用。 最廣泛使用的計數器應用程序是在EVM中以及在客戶反饋機中。

CODE

#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>
#define RS 0
#define EN 1
void lcd_comm	(char);
void lcd_data	(char);
void lcd_init	(void);
void lcd_string	(char*);
void lcd_num	(int n);
int main(void)
{
int c = 0;
DDRA = 0x00;
lcd_init();
lcd_comm(0x84);
lcd_string("COUNTER");
lcd_comm(0xC5);
lcd_data(c+48);
while(1)
{
if( (PINA & 0x01) == 1 )
{
c++;
lcd_comm(0xC5);
lcd_num(c);
while( (PINA & 0x01) == 1 );
}
}
}
void lcd_comm(char x){
PORTD = x;
PORTC &= ~(1<<RS);
PORTC |= 1<<EN;
_delay_ms(5);
PORTC &= ~(1<<EN);
}
void lcd_data(char x){
PORTD = x;
PORTC |= 1<<RS;
PORTC |= 1<<EN;
_delay_ms(5);
PORTC &= ~(1<<EN);
}
void lcd_init(void){
DDRD = 0xFF;
DDRC = 0x03;
lcd_comm(0x38);
lcd_comm(0x06);
lcd_comm(0x0E);
lcd_comm(0x01);
lcd_comm(0x80);
}
void lcd_string(char* p){
while(*p!='\0'){
lcd_data(*p);
p++;
}
}
void lcd_num(int n){
lcd_data((n/1000)+48);
n %= 1000;
lcd_data((n/100)+48);
n %= 100;
lcd_data((n/10)+48);
n %= 10;
lcd_data(n+48);
}

Explanation:

說明:

  • Firstly we have included all the header file that is required basically

    首先,我們包含了所有基本需要的頭文件

  • At the initial condition, we have defined EN=1 and RS=0.

    在初始條件下,我們定義了EN = 1和RS = 0 。

  • Next we have defined certain functions lcd_comm(char), lcd_data(char) and lcd_init(void) etc.

    接下來,我們定義了某些函數lcd_comm(char) , lcd_data(char)和lcd_init(void)等。

  • Inside the int main(void) we have created a variable c which is an integer and initially it is equal to zero. It will remember the number of times we will press our push button.

    在int main(void)內部,我們創建了一個變量c ,它是一個整數,最初它等于零。 它會記住我們按下按鈕的次數。

  • DDRA=0x00 says that we have connected a push button to PA0.

    DDRA = 0x00表示我們已將按鈕連接到PA0 。

    The

    lcd_init(); will run the lcd_init function that we have defined below.

    lcd_init(); 將運行下面定義的lcd_init函數。

    The command

    命令

    0x84 is made our string(COUNTER) in between of the LCD display

    0x84是我們在液晶顯示器之間的字符串(COUNTER)

    Lcd_string("COUNTER") will print COUNTER.

    Lcd_string(“ COUNTER”)將打印COUNTER。

    Lcd_data(c+48) is used to write our string in ASCII code.

    Lcd_data(c + 48)用于以ASCII代碼寫入我們的字符串。

  • Inside the while loop, we have written our condition if the button is pressed we add 1 to our variable c.

    在while循環內部,如果按下按鈕,我們就寫了條件,我們在變量c中加了1。

  • The command 0xCS will overwrite the initial zero condition of our counter.

    命令0xCS將覆蓋計數器的初始零條件。

  • Inside the void lcd_comm(char x), we have taken the variable as char x, which we have assigned to PORTD. In the next step we have masked the initial value of RS which was initially 0, and here we have made it 1. Next, we have made our Enable Pin high and then low by giving the time delay of 5ms in between.

    在void lcd_comm(char x)內 ,我們將變量指定為char x ,并將其分配給PORTD 。 在下一步中,我們屏蔽了RS的初始值,該值最初為0,在這里我們將其設置為1。接下來,通過在5ms之間設置時間延遲,將使能引腳設為高電平,然后設為低電平。

  • Again for the next function, we would be giving the data to LCD through this. We have taken a variable x, and assigned to PORTD, again made RS pin 0 and also have done similarly the Enable pin high and then low by providing the time delay of 5ms. In this function lcd_init(void), we have written all the commands that are required for the LCD at the beginning. The DDRD=0xFF indicates all the data pins connected to the PORTD, and DDRC=0x03 is for the connection of the ENABLE Pin and R/S pin we connected to PORTC.

    再次為下一個功能,我們將通過此將數據提供給LCD。 我們已將變量x分配給PORTD ,再次將其設為RS引腳0,并且通過提供5ms的時間延遲,同樣將Enable引腳設為高電平,然后設為低電平。 在此函數lcd_init(void)中 ,我們在一開始就編寫了LCD所需的所有命令。 DDRD = 0xFF表示連接到PORTD的所有數據引腳,而DDRC = 0x03用于連接我們連接到PORTC的ENABLE引腳和R / S引腳。

    0x38 - as the LCD is in 8 bit mode.

    0x38 -LCD處于8位模式。

    0x06 - cursor shifts to the right.

    0x06-光標向右移動。

    0x0E - display ON and cursor ON.

    0x0E-顯示打開,光標打開。

    0x01 - clears the screen.

    0x01-清除屏幕。

    Ox80 – 0th row and 0th column.

    Ox80 – 0行和 0列。

  • The function lcd_string(char *p) is used to print the words and are simple strings, here we have used them to print the word COUNTER.

    函數lcd_string(char * p)用于打印單詞,它們是簡單的字符串,這里我們使用它們來打印單詞COUNTER。

  • The void lcd_num(int n) function is used to display n which is equal to the number of times the button is pressed. Inside the function, we have defined three conditions for n to be a three digit number, a two digit number, and a single digit number. We have also used mod here so that we can get the accurate value of n.

    void lcd_num(int n)函數用于顯示n ,該n等于按鈕被按下的次數。 在函數內部,我們為n定義了三個條件,即三個數字,兩個數字和一個數字。 我們在這里還使用了mod,以便獲得n的準確值。

Simulation:

模擬:

Simulation of Create counter using an 8-bits LCD | AVR

Explanation:

說明:

  • Components required:

    所需組件:

    1. 1 resistor
    2. 2 ground terminal
    3. LM016L i.e. our LCD
    4. Atmega16
    5. Push button
    6. Power terminal
  • Make the connections as shown above.

    如上所示進行連接。

  • Double click on power terminal and edit its property to +5V.

    雙擊電源端子,然后將其屬性編輯為+ 5V。

  • Connected the resistor after the push button such that the high unwanted current goes directly ti it.

    在按鈕之后連接電阻,以使多余的高電流直接流過該電阻。

  • Double click the Atmega16 and debug the HEX file.

    雙擊Atmega16并調試HEX文件。

  • Click on the Run Button and your counter will run and the no. if times you will press the button will appear on the screen.

    單擊運行按鈕,您的計數器將運行,并且沒有。 如果您要按幾次,該按鈕將出現在屏幕上。

翻譯自: https://www.includehelp.com/embedded-system/create-counter-using-an-8-bits-lcd-avr.aspx

avr計數

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541838.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541838.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541838.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

php將字符變為數字,數字字符怎么轉化為數字 php 怎么將字符轉成數字

java中&#xff0c;String字符串轉化為數字我現在想把一個String字符串轉化為數字&#xff0c; String s"00000123" 我直接使java中String字符串轉化為數字&#xff1a; 轉換為浮點型&#xff1a; 使用Double或者Float的parseDouble或者parseFloat方法進行轉換 Strin…

用U盤作為啟動盤做系統步驟

步驟一&#xff1a;BIOS設置U盤啟動 制作好Win10 U盤系統安裝盤之后&#xff0c;我們需要在電腦的BIOS設置中把第一啟動設備設置為U盤&#xff0c;設置后就可以從我們制作的Win10 U盤系統安裝盤啟動&#xff0c;從而顯示系統安裝界面開始安裝系統。BIOS設置U盤啟動的方法如下&a…

使用tkinter模塊在Python中進行GUI編程

GUI (Graphical User Interface): GUI(圖形用戶界面)&#xff1a; GUI is a simple application which helps the user to interact with the computer or any other electronic device through a graphical icon. This used to perform different tasks on a desktop or lapt…

php輕博客社區視頻教程,輕博客主題 - SEO極致優化的ZBLOG輕博客主題

zblog自適應輕博客主題&#xff0c;簡潔、輕巧、極致優化~QQ群&#xff1a;457320274 (問題反饋以及其他鏈接交換等) 交流社區&#xff1a;https://www.bxiu.net/ (有問題可以求助交流)更新記錄&#xff1a;2021.02.22 v2.8 更新內容&#xff1a;1、新增分類自定義標題&#xf…

Composer學習之————Ubuntu14.04下安裝Composer

下載Composer&#xff1a; curl -sS https://getcomposer.org/installer | php 安裝Composer&#xff1a; /usr/bin/php composer.phar --version 設置全局命令&#xff1a; sudo mv composer.phar /usr/local/bin/composer 查看是否安裝與設置成功&#xff1a; composer -vers…

u盤啟動iso 開源_啟動和維護開源項目

u盤啟動iso 開源Lets talk about how to start an open-source project? The process can be classified as in three phases, 讓我們談談如何啟動一個開源項目&#xff1f; 該過程可以分為三個階段&#xff0c; Individual senses the need of the project: This is the pha…

java如何解決高并發癥,JAVA線上故障緊急處理詳細過程!

鏈接&#xff1a;https://fredal.xin/java-error-check?hmsrtoutiao.io&utm_mediumtoutiao.io&utm_sourcetoutiao.io線上故障主要會包括 CPU、磁盤、內存以及網絡問題&#xff0c;而大多數故障可能會包含不止一個層面的問題&#xff0c;所以進行排查時候盡量四個方面依…

程序員如何談加薪?

如果你對現在公司很滿意&#xff0c;只是覺得薪資太低&#xff0c;那么可以先和你的主管聊聊。 首先&#xff0c;講一講自己最近在工作上的成長&#xff0c;看主管是否認同&#xff1b; 然后&#xff0c;從能力提升角度&#xff0c;向主管要一個更大的發展空間和更大的業務挑戰…

php有多少魔術方法,PHP常用的幾個魔術方法

常用的魔術方法有&#xff1a;__Tostring () __Call() __autoLoad() __ clone() __GET() __SET() __isset() __unset()1.__Tostring()用于定義輸出對象引用時調用常用于打印一些對象的信息必須有返回值eg&#xff1a;有一個persion類Persion per new persion()Echo per; //直接…

python常用語法和示例_使用Python中的示例進行輸入和輸出操作

python常用語法和示例A Program needs to interact with the user to accomplish the desired task; this is done using Input-Output facility. Input means the data entered by the user of the program. In python, we have input() and raw_input ( ) function available…

關于node.js和npm 和nvm_byKL

關于node.js和npm 和nvm Node 是一個服務器端 JavaScript 解釋器&#xff0c;Node 本身運行 V8 JavaScript。V8 JavaScript 引擎是 Google 用于其 Chrome 瀏覽器的底層 JavaScript 引擎。 NPM是隨同NodeJS一起安裝的包管理工具&#xff0c;能解決NodeJS代碼部署上的很多問題&am…

php 查看擴展 代碼,[擴展推薦] 使用 PHP Insights 在終端查看 PHP 項目代碼質量

PHP Insights 是一個由 Nuno Maduro 發布的、可在控制臺進行 PHP 即時質量檢查的拓展包。在項目的 readme 文件中&#xff0c;可以發現 PHP Insights 的主要功能包含&#xff1a;代碼質量 與 代碼風格 分析一個針對于代碼 結構 和 復雜度 的漂亮的預覽界面在 Laravel、Symfon…

航空機票預訂c#代碼_航空公司座位預訂問題的C ++程序

航空機票預訂c#代碼Problem statement: Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: 問題陳述&#xff1a;編寫一個程序來分配飛機上的乘客座位。 假設小型飛機的座位編號如下&#xff1a; 1 A B C…

linux命令之which

which這個命令可以說并不常用&#xff0c;它的作用是查看可執行文件的位置&#xff0c;并返回第一個搜索結果。可執行文件也就是指的某個系統命令&#xff0c;但是這個命令的位置必須是在PATH路徑里存在的。截圖中 &#xff0c;pwd的位置在/bin/pwd,當然&#xff0c;這個路徑是…

線性代數向量乘法_向量的標量乘法| 使用Python的線性代數

線性代數向量乘法Prerequisite: Linear Algebra | Defining a Vector 先決條件&#xff1a; 線性代數| 定義向量 Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. In other words, a vector is a mat…

sonar掃描普通JAVA執行,SonarQube掃描源代碼的方法

SonarQube掃描源代碼的方法雷建鋒一、分析源代碼綜述一旦成功安裝了SonarQube平臺&#xff0c;您就可以開始安裝一個分析器并開始創建項目了。在第一次分析時&#xff0c;該平臺會自動創建一個項目。如果您需要在第一個分析之前在項目上設置一些配置&#xff0c;那么您可以選擇…

html的學習思維導圖

轉載于:https://www.cnblogs.com/lingdublog/p/6438088.html

php語言冒泡法,PHP實現冒泡排序算法的案例

PHP實現冒泡排序算法的案例發布時間&#xff1a;2020-10-23 17:39:38來源&#xff1a;億速云閱讀&#xff1a;84作者&#xff1a;小新這篇文章主要介紹PHP實現冒泡排序算法的案例&#xff0c;文中介紹的非常詳細&#xff0c;具有一定的參考價值&#xff0c;感興趣的小伙伴們一定…

線性代數分塊矩陣求逆矩陣_單位矩陣屬性(AI = A)| 使用Python的線性代數

線性代數分塊矩陣求逆矩陣Prerequisites: 先決條件&#xff1a; Defining Matrix 定義矩陣 Identity matrix 身份矩陣 numpy.matmul( ) matrix multiplication numpy.matmul()矩陣乘法 In linear algebra, the identity matrix, of size n is the n n square matrix with one…

MySQL5.7.17的簡單配置文件

#編譯安裝mysql5.7.17 [rootweb_1 data]# cat ../my.cnf [client]port3307socket/data/3307/mysql.sock[mysqld]user mysqlbasedir /usr/local/mysqldatadir /data/3307/dataport3307server-id 1socket/data/3307/mysql.sockcharacter-set-server utf8log-error /data/33…