A simple AVR access control system code

Publisher:学海飘香Latest update time:2012-08-16 Source: 51heiKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

After the 1602 and key program debugging, encoding, password comparison, gatekeeping, and some processing of error codes are improved, they will not be uploaded. Here I will only leave a very basic version backup for myself.

#define F_CPU 4000000
#includeAVR-20090313\avr\include\avr\io.h>
#include
#includeLCD1602.h>
typedef unsigned char uchar;
typedef unsigned int uint;
static char str1[]={"begining"}; //Power-on system working display
static char str2[]={"enter pass"}; //Start entering the password to open the door
static char str3[]={"set pass"}; //Enter the encoding display
//Port direction, '1' output, '0' input.
#define BUTION_DDRN DDRD //Button port direction
#define BUTION_PORT PORTD //Button port
#define BUTION_DDRN_INT(); DDRD=0xf0; //Button port direction initialization
#define BUTION_PORT_REL (PIND&0x0f)
static uchar sweep[4]={0xef,0xdf,0xbf,0x7f}; //Four lines of scan port value
uchar pass_buf[9]; //password cache unit
uchar bution(void); //Matrix key program
uchar set_scan(void); //Encoding key scanning program
int main(void)
{uchar i,j;
Lcd_Init(); //LCD initialization function
Lcd_SetXy(0,0); //Set display coordinate function
Lcd_PutStr(&str1[0]);
_delay_ms(500); //Delay 1 second
Lcd_Init(); //LCD initialization function
Lcd_SetXy(0,0); //Set display coordinate function
Lcd_PutStr(&str2[0]);
Lcd_SetXy(0,1); //Set display coordinate function
for(;;)
  {for(i=0;i<9;i++)
    {do{j=set_scan();//Encoding key
     if(j==0x01)j=0xfe;break;//j=0xfe encoding key pressed
     j=bution(); ///Key scan
     if((j!=0xff)&&(j!=0x0a))break;
     }while(1);
    if(j==0xfe)break;//j=0xfe coded button pressed
    pass_buf=j;
    if(j==0x0b)break;
    }
  if()
  }
return 0x00;
}
uchar bution(void) //Matrix key program
{uchar i, key_buf; //key value cache unit
BUTION_DDRN_INT(); //Button port direction initialization
for(i=0;i<4;i++)//four lines scan
  {BUTION_PORT=sweep[i]; //Scan line
  _delay_us(20);
  key_buf=BUTION_PORT_REL;
  if(key_buf!=0x0f)//A key is pressed
    {_delay_ms(20); //delay de-jitter
    if(key_buf==BUTION_PORT_REL)//Key confirmation
      {key_buf=(~key_buf)&0x0f;
      switch(key_buf)
        {case 0x01:key_buf=0x00;break;
        case 0x02:key_buf=0x01;break;
        case 0x04:key_buf=0x02;break;
        case 0x08:key_buf=0x03;break;
        default:key_buf=0xff;
        }
      key_buf=i*4+key_buf;
      switch(key_buf)
        {case 0x00:key_buf='1';break;//"1" key
        case 0x01:key_buf='2';break;//"2" key
        case 0x02:key_buf='3';break;//"3" key
        case 0x03:key_buf=0xff;break;//"" key

        case 0x04:key_buf='4';break;//"4" key
        case 0x05:key_buf='5';break;//"5" key
        case 0x06:key_buf='6';break;//"6" key
        case 0x07:key_buf=0xff;break;//"" key

        case 0x08:key_buf='7';break;//"7" key
        case 0x09:key_buf='8';break;//"8" key
        case 0x0a:key_buf='9';break;//"9" key
        case 0x0b:key_buf=0xff;break;//"" key

        case 0x0c:key_buf='*';break;//"*" key
        case 0x0d:key_buf='0';break;//"0" key
        case 0x0e:key_buf='#';break;//"#" key
        case 0x0f:key_buf=0xff;break;//"" key
        default:key_buf=0xff;
        }
      while(BUTION_PORT_REL!=0x0f)
      {_delay_us(20);
      while(BUTION_PORT_REL!=0x0f);
      }//Wait for the button to pop up
      break;//Pick out from four scans
      }
    else key_buf=0xff;
    }
  else key_buf=0xff;
  }
return key_buf;
}
uchar set_scan(void)
{
}

Keywords:AVR Reference address:A simple AVR access control system code

Previous article:Causes and solutions for AVR internal EEPROM data loss
Next article:LCD1602 driver based on atmega (8 lines/4 lines)

Recommended ReadingLatest update time:2024-11-16 21:22

avrI/O port operation and pull-up resistors
AVR MCU Port Operation Note: This section focuses on the operation of true bidirectional ports and the differences between true bidirectional port operation and pseudo bidirectional port operation. Marquee example. It is recommended to read the marquee first and then go back to read the previous introduction.     AV
[Microcontroller]
AVR MCU and GCC Programming Memory Operation
There are three types of independently addressed memories inside the AVR series microcontrollers, namely: Flash program memory, internal SRAM data memory, and EEPROM data memory. Flash memory is 1K~128K bytes, supports parallel programming and serial download, and the download life is usually up to 10,000 times. Si
[Microcontroller]
AVR microcontroller stopwatch Proteus simulation program TM1637 digital tube display
The microcontroller source program is as follows: /** *Copyright (c) 2018, 艁ukasz Marcin Podkalicki *December 13, 2009             *Simple timer (start/reset/stop) using one button and 7-segment display module based on TM1637.*             *Note that the internal clock used by this ATtiny13 project is not precise 
[Microcontroller]
AVR microcontroller stopwatch Proteus simulation program TM1637 digital tube display
AVR LCD12864 Program
/*********************************************************************         Purpose: Create LCD12864 operation library Target system: Based on AVR microcontroller                                                  Application software: ICCAVR                                                       Version: Version 1.0
[Microcontroller]
AVR-based escalator
1.1 Research Background Escalators are widely used in large shopping malls, supermarkets, airports, subways, hotels and other places. Most escalators work at rated operating conditions when there are large passenger flows, and still run at rated speeds when there are no passengers. They have the disadvantages of high
[Microcontroller]
AVR-based escalator
AVR microcontroller cannot enter programming mode
The AVR microcontroller ATmega16 was used in the project. The editing and compiling environment during the learning process was ICCAVR, and the parallel port downloader and PonyProg2000 software were used to download the program. When the project was almost done, considering that if I wanted to debug the program on
[Microcontroller]
AVR microcontroller cannot enter programming mode
AVR microcontroller infrared remote control key value decoding experiment
AVR Learning Notes XVIII: Infrared Remote Control Key Value Decoding Experiment   18.1 Example Function  Infrared remote control is currently the most widely used means of communication and remote control. Since infrared remote control devices have the characteristics of small size, low power consumption, strong func
[Microcontroller]
AVR microcontroller infrared remote control key value decoding experiment
AVR Studio Quick Start
For AVR Studio software download and installation methods, please refer to: Selection and Installation of AVR Development Software. After the software is installed, you will see the following function menu on your computer: Function 1: Write and compile assembly projects. (Not recommended) Ope
[Microcontroller]
AVR Studio Quick Start
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号