当前位置:网站首页>Press key to control LED status reversal
Press key to control LED status reversal
2022-06-27 01:48:00 【Let everything burn】
List of articles
Subject requirements
Through the programming environment KEIL Realization
Keycontrol LED State flip
requirement : Key controlled LED Point to or box for the same color LED

It is required to use the on the core board LED Lights and on the development board LED Is the synchronization state
Train of thought exploration
Two small lights on the core board
LED1 Positive connection PB0, Connect to the breadboard (GND)
When pb0 This port outputs a high level led1 Lighten up
How to latch : The port level is fixed ,while The above statement reads the port status , Then reverse . For example, the port used to be high level , Switch to low level .
About the eight small lights on the development board
Left full light
0x0F
All lights on the right
0xF0
All bright
0xFF
Total destruction
0x00
Because we need to use TM1604, therefore
hardware->TM1640.c
c/c+±>.\Hardware\Tm1640
int main (void){
// The main program
u8 c=0x01;
RCC_Configuration(); // System clock initialization
RTC_Config(); //RTC initialization
TM1640_Init(); //TM1640 initialization
while(1){
if(RTC_Get()==0){
// read out RTC Time
TM1640_display(0,rday/10); // God
TM1640_display(1,rday%10+10);
TM1640_display(2,rhour/10); // when
TM1640_display(3,rhour%10+10);
TM1640_display(4,rmin/10); // branch
TM1640_display(5,rmin%10+10);
TM1640_display(6,rsec/10); // second
TM1640_display(7,rsec%10);
TM1640_led(c); // And TM1640 Connected 8 individual LED All bright
c<<=1; // Data shift left Running water lamp
if(c==0x00)c=0x01; //8 Restart after the first light is displayed
delay_ms(125); // Time delay
}
}
}
Code
main.c
int main (void){
// The main program
// Initializer
RCC_Configuration(); // The clock is set
LED_Init();//LED initialization
KEY_Init();// Key initialization
TM1640_Init(); //TM1640 initialization
// Main circulation
// Initialize the initial state to prevent garbled code from interfering with the program
TM1640_led(0x00);
while(1){
// There is a latch Press on for the first time Press the button for the second time
// Control the... On the core board LED1
if(!GPIO_ReadInputDataBit(KEYPORT,KEY1)){
// Read the level of the key interface
delay_ms(20); // Delay de jitter
if(!GPIO_ReadInputDataBit(KEYPORT,KEY1)){
// Read the level of the key interface
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(1-GPIO_ReadOutputDataBit(LEDPORT,LED1))); //LED Take the opposite
// Control the corresponding four small lights on the development board LED1 Sync
if( GPIO_ReadOutputDataBit(LEDPORT,LED1)==1)
TM1640_led(0x0F);
else
TM1640_led(0x00);
while(!GPIO_ReadInputDataBit(KEYPORT,KEY1)); // Wait for the key to release Prevent the program from running repeatedly without releasing the key
}
}
// Control the... On the core board LED2
if(!GPIO_ReadInputDataBit(KEYPORT,KEY2)){
// Read the level of the key interface
delay_ms(20); // Delay de jitter
if(!GPIO_ReadInputDataBit(KEYPORT,KEY2)){
// Read the level of the key interface
GPIO_WriteBit(LEDPORT,LED2,(BitAction)(1-GPIO_ReadOutputDataBit(LEDPORT,LED2))); //LED Take the opposite
// Control the corresponding four small lights on the development board LED2 Sync
if( GPIO_ReadOutputDataBit(LEDPORT,LED2)==1)
TM1640_led(0xF0);
else
TM1640_led(0x00);
while(!GPIO_ReadInputDataBit(KEYPORT,KEY2)); // Wait for the key to release Prevent the program from running repeatedly without releasing the key
}
}
// The above is divided into two parts
// The following solves the overall problem
// Both lights are on at the same time + Eight lights are on at the same time
if( GPIO_ReadOutputDataBit(LEDPORT,LED1)==1&&GPIO_ReadOutputDataBit(LEDPORT,LED2)==1)
TM1640_led(0xFF);
// At the same time LED flashing , Add a delay and you won't flash
delay_ms(125); // Time delay
// Separate control
if( GPIO_ReadOutputDataBit(LEDPORT,LED1)==1)
TM1640_led(0x0F);
if( GPIO_ReadOutputDataBit(LEDPORT,LED2)==1)
TM1640_led(0xF0);
}
}
边栏推荐
猜你喜欢

福元医药上市在即:募资净额将达到16亿元,胡柏藩为实际控制人

宁愿去996也不要待业在家啦!24岁,失业7个月,比上班更惨的,是没班可上

XSS notes (Part 2)

I encountered some problems when connecting to the database. How can I solve them?

执念斩长河暑期规划

Break through the performance bottleneck of image recognition through rust language computing acceleration technology

Summary of config mechanism and methods in UVM (2)

SQLite Reader 插件测试SQLite语法

markdown表格(合并)

CLIP:从自然语言监督中学习可迁移的视觉模型
随机推荐
Oracle/PLSQL: Translate Function
UVM中uvm_config_db非直线的设置与获取
Oracle/PLSQL: To_ Clob Function
XSS攻击(笔记)
1.44 inch TFT-LCD display screen mold taking tutorial
Systematic analysis of social networks using Networkx: Facebook network analysis case
Simply learn the entry-level concepts of googlecolab
Oracle/PLSQL: VSize Function
Shell脚本系列篇(1) 入门
接口测试框架实战(一) | Requests 与接口请求构造
canvas粒子篇之鼠标跟随js特效
Nokov motion capture system makes it possible for multi field cooperative UAV to build independently
uvm中的config机制方法总结(二)
XSS notes (Part 2)
get_ Usage Summary of sequencer
理想L9产品力分析:售价45.98万,采用四缸发动机,续航1315公里
接口隔离原则
每日刷题记录 (五)
Oracle/PLSQL: Upper Function
Oracle/PLSQL: Replace Function