紅外遙控接收;=================================================;; zsMCU51實驗板配套學(xué)習(xí)例程;; 中山單片機學(xué)習(xí)網(wǎng) 智佳科技;; 作者:逸風(fēng) QQ:105558851;; http://www.zsmcu.com; E-mail:info@zsmcu.com;=================================================ORG 0000HLJMP START;轉(zhuǎn)入主程序ORG 0010HSTART:Main:JNB P2.2,IRLJMP Main;以下為進入P3.2腳外部中斷子程序,也就是解碼程序IR:MOV R6,#9SB:ACALL DELAY882 ;調(diào)用882微秒延時子程序JB P2.2,EXIT ;延時882微秒后判斷P3.2腳是否出現(xiàn)高電平如果有就退出解碼程序DJNZ R6, SB ;重復(fù)10次,目的是檢測在8820微秒內(nèi)如果出現(xiàn)高電平就退出解碼程序;以上完成對遙控信號的9000微秒的初始低電平信號的識別。JNB P2.2, $ ;等待高電平避開9毫秒低電平引導(dǎo)脈沖ACALL DELAY2400JNB P2.2,IR_Rp ;ACALL DELAY2400 ;延時4.74毫秒避開4.5毫秒的結(jié)果碼MOV R1,#1AH ;設(shè)定1AH為起始RAM區(qū)MOV R2,#4PP:MOV R3,#8JJJJ:JNB P2.2,$ ;等待地址碼第一位的高電平信號LCALL DELAY882 ;高電平開始后用882微秒的時間尺去判斷信號此時的高低電平狀態(tài)MOV C,P2.2 ;將P3.2引腳此時的電平狀態(tài)0或1存入C中
JNC UUU ;如果為0就跳轉(zhuǎn)到UUULCALL DELAY1000UUU:MOV A,@R1 ;將R1中地址的給ARRC A ;將C中的值0或1移入A中的最低位MOV @R1,A ;將A中的數(shù)暫時存放在R1中DJNZ R3,JJJJ ;接收地址碼的高8位INC R1 ;對R1中的值加1,換下一個RAMDJNZ R2,PP ;接收完16位地址碼和8位數(shù)據(jù)碼和8位數(shù)據(jù),存放在1AH/1BH/1CH/1DH的RAM中MOV P1,1DH ;將按鍵的鍵值通過P1口的8個LED顯示出來!CLR P2.3 ;蜂鳴器鳴響-嘀嘀嘀-的聲音,表示解碼成功LCALL DELAY2400LCALL DELAY2400LCALL DELAY2400SETB P2.3;蜂鳴器停止LJMP MainIR_Rp:LJMP MainEXIT:LJMP Main ;退出解碼子程序;=============================882DELAY882: ;1.085x ((202x4)+5)=882MOV R7,#202DELAY882_A:NOPNOPDJNZ R7,DELAY882_ARET;=============================1000DELAY1000: ;1.085x ((229x4)+5)=999.285MOV R7,#229DELAY1000_A:NOPNOPDJNZ R7,DELAY1000_ARET;=============================2400
標簽:
紅外遙控
接收程序
上傳時間:
2013-11-01
上傳用戶:2525775
16 16點陣顯示漢字原理及顯示程序
#include "config.h"
#define DOTLED_LINE_PORT PORTB #define DOTLED_LINE_DDR DDRB #define DOTLED_LINE_PIN PINB
#define DOTLED_LINE_SCKT PB1 #define DOTLED_LINE_SCKH PB5 #define DOTLED_LINE_SDA PB3
#define DOTLED_ROW_PORT PORTC #define DOTLED_ROW_DDR DDRC #define DOTLED_ROW_PIN PINC
#define DOTLED_ROW_A0 PC0 #define DOTLED_ROW_A1 PC1 #define DOTLED_ROW_A2 PC2 #define DOTLED_ROW_A3 PC3 #define DOTLED_ROW_E PC4 uint8 font[] = { /*-- 調(diào)入了一幅圖像:這是您新建的圖像 --*/ /*-- 寬度x高度=16x16 --*/ 0x00,0x00,0x00,0x00,0x08,0x38,0x18,0x44,0x08,0x44,0x08,0x04,0x08,0x08,0x08,0x10, 0x08,0x20,0x08,0x40,0x08,0x40,0x08,0x40,0x3E,0x7C,0x00,0x00,0x00,0x00,0x00,0x00 }; static void TransmitByte(uint8 byte); static void SelectRow(uint8 row); static void FlipLatchLine(void);
static void TransmitByte(uint8 byte) { uint8 i; for(i = 0 ; i < 8 ; i ++) { if(byte & (1 << i)) { DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA); } else { DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SDA); } //__delay_cycles(100); DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKH); //__delay_cycles(100); DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKH); //__delay_cycles(100); } }
static void SelectRow(uint8 row) { //row -= 1; row |= DOTLED_ROW_PIN & 0xe0; DOTLED_ROW_PORT = row; }
static void FlipLatchLine(void) { DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKT); DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKT); }
void InitDotLedPort(void) { DOTLED_LINE_PORT &= ~(_BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH)); DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA); DOTLED_LINE_DDR |= _BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH) | _BV(DOTLED_LINE_SDA); DOTLED_ROW_PORT |= 0x1f; DOTLED_ROW_PORT &= 0xf0; DOTLED_ROW_DDR |= 0x1f; } void EnableRow(boolean IsEnable) { if(IsEnable) { DOTLED_ROW_PORT &= ~_BV(DOTLED_ROW_E); } else { DOTLED_ROW_PORT |= _BV(DOTLED_ROW_E); } } void PrintDotLed(uint8 * buffer) { uint8 i , tmp; for(i = 0 ; i < 16 ; i ++) { tmp = *buffer ++; TransmitByte(~tmp); tmp = *buffer ++; TransmitByte(~tmp); SelectRow(i); FlipLatchLine(); } } void Main(void) { InitDotLedPort(); EnableRow(TRUE); while(1) { PrintDotLed(font); __delay_cycles(5000); } }
//---------------------------------------------------- config.h文件
#ifndef _CONFIG_H #define _CONFIG_H
//#define GCCAVR
#define CPU_CYCLES 7372800L
#ifndef GCCAVR #define _BV(bit) (1 << (bit)) #endif
#define MSB 0x80 #define LSB 0x01
#define FALSE 0 #define TRUE 1 typedef unsigned char uint8; typedef unsigned int uint16; typedef unsigned long uint32; typedef unsigned char boolean; #include <ioavr.h> #include <inavr.h>
#include "dotled.h" #endif
//-----
標簽:
16
點陣顯示
漢字
顯示程序
上傳時間:
2013-11-18
上傳用戶:mnacyf