rfid_demo.rar

  • mastro_mmm
    了解作者
  • C/C++
    开发工具
  • 52KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 2
    下载次数
  • 2020-08-23 20:26
    上传日期
rfid function for avr
rfid_demo.rar
内容介绍
/****************************************************************************** eXtreme Electronics xAPI(TM) ---------------------------- xAPI is a Powerful but easy to use C library to program the xBoard(TM) series of AVR development board. The library has support for common tasks like:- *LCD interfacing *Multiplexed 7 segment displays. *Remote Control *Serial Communication *DC Motor Controls with Speed Control *Analog Measurement for Sensor Interface. *Temperature Measurement. *I2C Communication. *EEPROM Interface *Real Time Clock (RTC Interface) The APIs are highly documented and easy to use even by a beginner. For More Info Log On to www.eXtremeElectronics.co.in Copyright 2008-2013 eXtreme Electronics India LOG: 20 Oct 2013: * Fixed LS_NONE [SIMULATION TEST OK, HARDWARE TEST OK] * Fixed negative int printing. [SIMULATION TEST OK] * 16x2 LCD Positioning test ok * 20x2 LCD Positioning test ok * 20x4 LCD Positioning test ok * 16x4 LCD Positioning test ok [SIMULATION ONLY] * Every thing's done ! Ready for distribution. TODO: * Long int (32 bit) printing support. * Floating point printing support. LCD Core ---------- This module is used for driving Standard Alpha Numeric LCD Modules. For More information please see supplied tutorials and videos. NOTICE -------- NO PART OF THIS WORK CAN BE COPIED, DISTRIBUTED OR PUBLISHED WITHOUT A WRITTEN PERMISSION FROM EXTREME ELECTRONICS INDIA. THE LIBRARY, NOR ANY PART OF IT CAN BE USED IN COMMERCIAL APPLICATIONS. IT IS INTENDED TO BE USED FOR HOBBY, LEARNING AND EDUCATIONAL PURPOSE ONLY. IF YOU WANT TO USE THEM IN COMMERCIAL APPLICATION PLEASE WRITE TO THE AUTHOR. WRITTEN BY: AVINASH GUPTA me@avinashgupta.com *******************************************************************************/ #include <avr/io.h rel='nofollow' onclick='return false;'> #include <util/delay.h> #include <avr/pgmspace.h rel='nofollow' onclick='return false;'> #include <inttypes.h> #include "lcd_hd44780_avr.h" //Custom Charset support #include "custom_char.h" #define _CONCAT(a,b) a##b #define PORT(x) _CONCAT(PORT,x) #define PIN(x) _CONCAT(PIN,x) #define DDR(x) _CONCAT(DDR,x) #define LCD_DATA_PORT PORT(LCD_DATA) #define LCD_E_PORT PORT(LCD_E) #define LCD_RS_PORT PORT(LCD_RS) #define LCD_RW_PORT PORT(LCD_RW) #define LCD_DATA_DDR DDR(LCD_DATA) #define LCD_E_DDR DDR(LCD_E) #define LCD_RS_DDR DDR(LCD_RS) #define LCD_RW_DDR DDR(LCD_RW) #define LCD_DATA_PIN PIN(LCD_DATA) #define SET_E() (LCD_E_PORT|=(1<<LCD_E_POS)) #define SET_RS() (LCD_RS_PORT|=(1<<LCD_RS_POS)) #define SET_RW() (LCD_RW_PORT|=(1<<LCD_RW_POS)) #define CLEAR_E() (LCD_E_PORT&=(~(1<<LCD_E_POS))) #define CLEAR_RS() (LCD_RS_PORT&=(~(1<<LCD_RS_POS))) #define CLEAR_RW() (LCD_RW_PORT&=(~(1<<LCD_RW_POS))) #ifdef LCD_TYPE_162 #define LCD_TYPE_204 #endif #ifdef LCD_TYPE_202 #define LCD_TYPE_204 #endif void LCDByte(uint8_t c,uint8_t isdata) { //Sends a byte to the LCD in 4bit mode //isdata=1 for data //isdata=0 for command //NOTE: THIS FUNCTION RETURS ONLY WHEN LCD HAS COMPLETED PROCESSING THE COMMAND uint8_t hn,ln; //Nibbles uint8_t temp; hn=c>>4; ln=(c & 0x0F); if(isdata==0) CLEAR_RS(); else SET_RS(); _delay_us(0.500); //tAS SET_E(); //Send high nibble temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((hn<<LCD_DATA_POS)); LCD_DATA_PORT=temp; _delay_us(1); //tEH //Now data lines are stable pull E low for transmission CLEAR_E(); _delay_us(1); //Send the lower nibble SET_E(); temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((ln<<LCD_DATA_POS)); LCD_DATA_PORT=temp; _delay_us(1); //tEH //SEND CLEAR_E(); _delay_us(1); //tEL LCDBusyLoop(); } void LCDBusyLoop() { //This function waits till lcd is BUSY uint8_t busy,status=0x00,temp; //Change Port to input type because we are reading data LCD_DATA_DDR&=(~(0x0f<<LCD_DATA_POS)); //change LCD mode SET_RW(); //Read mode CLEAR_RS(); //Read status //Let the RW/RS lines stabilize _delay_us(0.5); //tAS do { SET_E(); //Wait tDA for data to become available _delay_us(0.5); status=(LCD_DATA_PIN>>LCD_DATA_POS); status=status<<4; _delay_us(0.5); //Pull E low CLEAR_E(); _delay_us(1); //tEL SET_E(); _delay_us(0.5); temp=(LCD_DATA_PIN>>LCD_DATA_POS); temp&=0x0F; status=status|temp; busy=status & 0b10000000; _delay_us(0.5); CLEAR_E(); _delay_us(1); //tEL }while(busy); CLEAR_RW(); //write mode //Change Port to output LCD_DATA_DDR|=(0x0F<<LCD_DATA_POS); } void LCDInit(uint8_t style) { /***************************************************************** This function Initializes the lcd module must be called before calling lcd related functions Arguments: style = LS_BLINK,LS_ULINE(can be "OR"ed for combination) LS_BLINK :The cursor is blinking type LS_ULINE :Cursor is "underline" type else "block" type *****************************************************************/ //After power on Wait for LCD to Initialize _delay_ms(100); //Clear Ports LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS)); CLEAR_E(); CLEAR_RW(); CLEAR_RS(); //Set IO Ports direction LCD_DATA_DDR|=(0x0F<<LCD_DATA_POS); //data line direction LCD_E_DDR|=(1<<LCD_E_POS); //E line line direction LCD_RS_DDR|=(1<<LCD_RS_POS); //RS line direction LCD_RW_DDR|=(1<<LCD_RW_POS); //RW line direction //Reset sequence /* _delay_us(0.3); //tAS SET_E(); LCD_DATA_PORT|=((0b00000011)<<LCD_DATA_POS); _delay_us(1); CLEAR_E(); _delay_us(1); _delay_ms(10); SET_E(); LCD_DATA_PORT|=((0b00000011)<<LCD_DATA_POS); _delay_us(1); CLEAR_E(); _delay_us(1); _delay_us(200); SET_E(); LCD_DATA_PORT|=((0b00000011)<<LCD_DATA_POS); _delay_us(1); CLEAR_E(); _delay_us(1); _delay_us(200); */ //Reset sequence END //Set 4-bit mode _delay_us(0.3); //tAS SET_E(); LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000 _delay_us(1); CLEAR_E(); _delay_us(1); //Wait for LCD to execute the Functionset Command //LCDBusyLoop(); //[B] Forgot this delay _delay_us(300); //Now the LCD is in 4-bit mode LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format LCDCmd(0b00001000|style); //Display Off LCDCmd(0b00001100|style); //Display On /* Custom Char */ LCDCmd(0b01000000); uint8_t __i; for(__i=0;__i<sizeof(__cgram);__i++) LCDData(__cgram[__i]); LCDClear(); } void LCDWriteString(const char *msg) { /***************************************************************** This function Writes a given string to lcd at the current cursor location. Arguments: msg: a null terminated string to print Their are 8 custom char in the LCD they can be defined using "LCD Custom Character Builder" PC Software. You can print custom character using the % symbol. For example to print custom char number 0 (which is a degree symbol), you need to write LCDWriteString("Temp is 30%0C"); ^^ |----> %0 will be replaced by custom char 0. So it will be printed like. Temp is 30�C In the same way you can insert any syblom numbered 0-7 *****************************************************************/ while(*msg!='\0') { //Custom Char Support if(*msg=='%') { msg++; int8_t cc=*msg-'0'; if(cc>=0 && cc<=7) { LCDData(cc); } else { LCDData('%'); LCDData(*msg); } } else { LCDData(*msg); } msg++; } } void LCDWriteFString(const char *msg) { /*****************************************************************
评论
    相关推荐