亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標(biāo)題:
基于單片機(jī)+lcd12864的英文記事本程序設(shè)計(jì)
[打印本頁(yè)]
作者:
1723570136
時(shí)間:
2019-1-10 20:24
標(biāo)題:
基于單片機(jī)+lcd12864的英文記事本程序設(shè)計(jì)
系統(tǒng)通電后,要輸入
6
位的密碼才能進(jìn)入系統(tǒng)。進(jìn)入系統(tǒng)后,可以輸入英文文章。即系統(tǒng)按鍵具有數(shù)字、標(biāo)點(diǎn)符號(hào)、大小寫字母、空格,回車等字符輸入功能。附加功能為進(jìn)入系統(tǒng)后,密碼可以用按鍵更改;輸入的文章,液晶界面顯示滿之后,能夠分頁(yè)切換,并且具有保存、清楚功能。
單片機(jī)源程序如下:
/**
* note.c
*
* Created At: 2018-12-17
* Author: yowfung
* Description: 英文記事本程序
*/
#include <reg52.h>
#include "../inc/public.h"
#include "../inc/lcd12864.h"
#include "../inc/keys.h"
/**
* 定義常量
*/
const unsigned char PASSWORD_CONTENT[7] = "yowfung"; // 登錄密碼
const unsigned char PASSWORD_LENGTH = 7; // 密碼長(zhǎng)度
/**
* 聲明函數(shù)
*/
bit ValidatePassword();
void Editor(void);
void insCharToStr(unsigned char *str, unsigned char ch, unsigned int index);
void delCharFromStr(unsigned char *str, unsigned int index);
void WriteContent(unsigned char *content, unsigned char length);
void setLcdPos(unsigned char pos);
/**
* 英文記事本程序運(yùn)行
*
* 需要連接的線路:
* 1. LCD12864電路: RS -> P0.0
* RW -> P0.1
* E -> P0.2
* D0~D7 -> P1.0~1.7
* 2. 矩陣按鍵電路: Row1~9 -> P2.0~2.7,P0.7
* Col1~6 -> P3.2~3.7
* 3. Shift狀態(tài)燈電路:LED -> P0.3
*
* 功能及流程描述:
* 1. 運(yùn)行后LCD上第一行顯示“Hello YowFung”,第二行顯示“NoteBook”;
* 2. 5秒后出現(xiàn)密碼輸入界面,通過按鍵輸入六位數(shù)密碼,然后按Enter鍵,密碼
* 正確則進(jìn)入編輯狀態(tài),否則顯示“Password Error!”3秒并回到密碼輸入
* 界面;
* 3. 在編輯狀態(tài)中,通過按鍵輸入字符,每輸入一個(gè)字符光標(biāo)向右移動(dòng)一位,當(dāng)
* 一行顯示滿了后,則在下一行顯示,當(dāng)一個(gè)屏幕都顯示滿了后,則可以通過
* 按 Up 或 Down 鍵來滾動(dòng)屏幕;
* 4. 按 ← 或 → 鍵可以左右移動(dòng)光標(biāo);
* 5. 按 Clear 鍵可以清屏;
* 6. 按 Del 鍵可以刪除當(dāng)前光標(biāo)左邊的一個(gè)字符;
* 7. 按下 Shift 鍵時(shí),Shift 狀態(tài) LED 燈被點(diǎn)亮,此時(shí)輸入的字符為第二字
* 符,再按一次 Shift 鍵,LED 滅,回到第一字符輸入狀態(tài)。
*/
void note_run(void)
{
bit vali_res = 0;
// 初始化 LCD12864
Lcd12864_init();
// 顯示歡迎界面
Lcd12864_wrLine(2, " Hello YowFung");
Lcd12864_wrLine(3, " NoteBook");
delay(3000);
// 輸入登錄密碼,直到密碼正確
do {
// 清屏
Lcd12864_cls();
delay(500);
// 輸入密碼并驗(yàn)證
vali_res = ValidatePassword();
// 如果密碼錯(cuò)誤則顯示錯(cuò)誤信息
if (vali_res == 0) {
Lcd12864_cls();
Lcd12864_showCursor(0);
Lcd12864_wrLine(2, "Password Error,");
Lcd12864_wrLine(3, "Input Again!");
delay(2000);
}
} while (vali_res == 0);
// 密碼輸入正確,顯示歡迎信息
Lcd12864_cls();
Lcd12864_showCursor(0);
Lcd12864_wrLine(2, " Welcome Back!");
delay(2000);
// 進(jìn)入編輯界面
Editor();
while(1);
}
/**
* 檢測(cè)登錄密碼輸入并驗(yàn)證
*
*/
bit ValidatePassword()
{
unsigned char input, length = 0, ch, ct, i;
unsigned char pass_in[7] = {0x00}; // 全部顯示空格
unsigned char pass_show[7] = {0x20}; // 密碼默認(rèn)為空
bit result = 1;
// 提示輸入登錄密碼的界面
Lcd12864_wrLine(1, " Login Password");
Lcd12864_wrLine(2, " ^^^^^^^^^^^^^^ ");
Lcd12864_wrLine(3, "> <");
Lcd12864_wrLine(4, " -------------- ");
Lcd12864_setPos(3, 2);
Lcd12864_showCursor(1);
delay(500);
// 監(jiān)測(cè)按鍵輸入(同時(shí)監(jiān)測(cè)字符按鍵和控制按鍵)
while (1) {
input = Keys_get9x6Num();
delay(20);
if (input == 0)
// 如果沒有按下任何鍵
continue;
else {
// 取出按下的控制鍵碼
ct = Keys_get9x6Ctrl(input);
if (ct != NULL_CHAR) {
switch (ct) {
case CTRL_SHIFT : { // 切換 Shift 輸入狀態(tài)
Keys_setShift(!Keys_getShift());
}; break;
case CTRL_DEL : { // 柵格
if (length) {
length--;
pass_show[length] = 0x20;
pass_in[length] = 0x00;
}
}; break;
case CTRL_CLS : { // 清屏
length = 0;
for (i = 0; i < 7; i++) {
pass_show[i] = 0x20;
pass_in[i] = 0x00;
}
}; break;
case CTRL_ENT : { // 回車
for (i = 0; i < 7; i++) {
if (pass_in[i] != PASSWORD_CONTENT[i]) {
result = 0;
break;
}
}
return result;
}; break;
}
}
// 如果已經(jīng)輸滿了,則不再監(jiān)測(cè)字符輸入
if (length != PASSWORD_LENGTH) {
// 取出按下的字符
ch = Keys_get9x6Char(input);
if (ch != NULL_CHAR) {
pass_in[length] = ch;
pass_show[length] = '*';
length++;
}
}
}
// 顯示輸入情況
Lcd12864_wrLine(3, "| |");
Lcd12864_setPos(3, 2);
Lcd12864_wrStr(pass_show, 7);
Lcd12864_setPos(3, 2 + length/2);
}
}
/**
* 記事本編輯器
*/
void Editor(void)
{
unsigned char input, ch, ct, i, j;
unsigned char length = 0; // 字符長(zhǎng)度
unsigned char content[64] = {0x20}; // 字符串內(nèi)容
unsigned char pos = 0; // 光標(biāo)位置
// 清屏,顯示光標(biāo)
Lcd12864_cls();
Lcd12864_showCursor(1);
delay(500);
while(1) {
// 監(jiān)測(cè)按鍵輸入
input = Keys_get9x6Num();
delay(20);
if (input == 0)
// 如果沒有按鍵輸入則跳過
continue;
else {
// 監(jiān)測(cè)是否為控制鍵碼
ct = Keys_get9x6Ctrl(input);
if (ct != NULL_CHAR) {
switch (ct) {
case CTRL_CLS : { // 清屏
Lcd12864_cls();
length = 0;
pos = 0;
for (i = 0; i < 64; i++)
content[i] = 0x20;
}; continue;
case CTRL_DEL : { // 柵格
if (pos != 0) {
pos--;
delCharFromStr(content, pos);
length--;
}
}; break;
case CTRL_SHIFT : { // 切換 Shift 輸入狀態(tài)
Keys_setShift(!Keys_getShift());
}; continue;
case CTRL_UP : { // 向上移動(dòng)光標(biāo)
if (pos >= 16) {
pos -= 16;
setLcdPos(pos);
}
}; continue;
case CTRL_DOWN : { // 向下移動(dòng)光標(biāo)
if (pos + 16 < length) {
pos += 16;
setLcdPos(pos);
}
}; continue;
case CTRL_LEFT : { // 向左移動(dòng)光標(biāo)
if (pos != 0) {
pos--;
setLcdPos(pos);
}
}; continue;
case CTRL_RIGHT : { // 向右移動(dòng)光標(biāo)
if (pos < length - 1) {
pos++;
setLcdPos(pos);
}
}; continue;
}
}
// 監(jiān)測(cè)是否為字符按鍵
ch = Keys_get9x6Char(input);
if (ch != NULL_CHAR) {
insCharToStr(content, ch, pos);
pos++;
length++;
if (pos > 63)
pos = 63;
if (length > 64)
length = 64;
}
// 顯示記事本文本內(nèi)容
WriteContent(content, length);
// 設(shè)置光標(biāo)位置
setLcdPos(pos);
}
}
}
/**
* 插入字符到字符串中
* @param str 字符串
* @param ch 欲插入的字符
* @param index 插入位置
*/
void insCharToStr(unsigned char str[], unsigned char ch, unsigned int index)
{
unsigned int i = 0;
unsigned char tmp1, tmp2;
while(i < 64) {
if (i == index) {
tmp1 = str[i];
str[i] = ch;
} else if (i > index) {
tmp2 = str[i];
str[i] = tmp1;
tmp1 = tmp2;
}
i++;
}
}
/**
* 從字符串中刪除指定位置處的字符
* @param str 字符串
* @param index 欲刪除字符的位置
*/
void delCharFromStr(unsigned char str[], unsigned int index)
{
unsigned int i = 0;
while(i < 64) {
if (i >= index) {
if (i == 63)
str[i] = 0x20;
else {
str[i] = str[i+1];
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
英文記事本.zip
(145.44 KB, 下載次數(shù): 28)
2019-1-10 20:23 上傳
點(diǎn)擊文件名下載附件
英文記事本
下載積分: 黑幣 -5
作者:
yowfung
時(shí)間:
2019-1-29 15:16
把別人的代碼原封不動(dòng)的發(fā)上來,也不征求原作者的同意?也不注明原創(chuàng)?
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1