使用P1.0~P1.7与D0~D7相接,EN,RW,RS分别与P0.7,P0.6,P0.5相接
(四)蓝牙与单片机连接
这里直接用P3.0,P3.1与主机的串口通信和与蓝牙共用串口。
(五)LN298模块
4 系统软件设计
#include \#include \#include \#include \
#define MAIN_Fosc 11059200L //定义主时钟 /************* 变量声明 **************/ typedef unsigned char u8; typedef unsigned int u16; typedef unsigned long u32; typedef unsigned char BYTE; typedef unsigned int WORD; #define uchar unsigned char #define uint unsigned int #define elif else if
#define PWMC (*(unsigned int volatile xdata *)0xfff0) #define PWMCH (*(unsigned char volatile xdata *)0xfff0) #define PWMCL (*(unsigned char volatile xdata *)0xfff1) #define PWMCKS (*(unsigned char volatile xdata *)0xfff2) #define PWM2T1 (*(unsigned int volatile xdata *)0xff00) #define PWM2T1H (*(unsigned char volatile xdata *)0xff00) #define PWM2T1L (*(unsigned char volatile xdata *)0xff01) #define PWM2T2 (*(unsigned int volatile xdata *)0xff02) #define PWM2T2H (*(unsigned char volatile xdata *)0xff02) #define PWM2T2L (*(unsigned char volatile xdata *)0xff03) #define PWM2CR (*(unsigned char volatile xdata *)0xff04) #define PWM3T1 (*(unsigned int volatile xdata *)0xff10) #define PWM3T1H (*(unsigned char volatile xdata *)0xff10) #define PWM3T1L (*(unsigned char volatile xdata *)0xff11) #define PWM3T2 (*(unsigned int volatile xdata *)0xff12) #define PWM3T2H (*(unsigned char volatile xdata *)0xff12)
#define PWM3T2L (*(unsigned char volatile xdata *)0xff13) #define PWM3CR (*(unsigned char volatile xdata *)0xff14) #define PWM4T1 (*(unsigned int volatile xdata *)0xff20) #define PWM4T1H (*(unsigned char volatile xdata *)0xff20) #define PWM4T1L (*(unsigned char volatile xdata *)0xff21) #define PWM4T2 (*(unsigned int volatile xdata *)0xff22) #define PWM4T2H (*(unsigned char volatile xdata *)0xff22) #define PWM4T2L (*(unsigned char volatile xdata *)0xff23) #define PWM4CR (*(unsigned char volatile xdata *)0xff24) #define PWM5T1 (*(unsigned int volatile xdata *)0xff30) #define PWM5T1H (*(unsigned char volatile xdata *)0xff30) #define PWM5T1L (*(unsigned char volatile xdata *)0xff31) #define PWM5T2 (*(unsigned int volatile xdata *)0xff32) #define PWM5T2H (*(unsigned char volatile xdata *)0xff32) #define PWM5T2L (*(unsigned char volatile xdata *)0xff33) #define PWM5CR (*(unsigned char volatile xdata *)0xff34) #define PWM6T1 (*(unsigned int volatile xdata *)0xff40) #define PWM6T1H (*(unsigned char volatile xdata *)0xff40) #define PWM6T1L (*(unsigned char volatile xdata *)0xff41) #define PWM6T2 (*(unsigned int volatile xdata *)0xff42) #define PWM6T2H (*(unsigned char volatile xdata *)0xff42) #define PWM6T2L (*(unsigned char volatile xdata *)0xff43) #define PWM6CR (*(unsigned char volatile xdata *)0xff44) #define PWM7T1 (*(unsigned int volatile xdata *)0xff50) #define PWM7T1H (*(unsigned char volatile xdata *)0xff50) #define PWM7T1L (*(unsigned char volatile xdata *)0xff51) #define PWM7T2 (*(unsigned int volatile xdata *)0xff52) #define PWM7T2H (*(unsigned char volatile xdata *)0xff52) #define PWM7T2L (*(unsigned char volatile xdata *)0xff53) #define PWM7CR (*(unsigned char volatile xdata *)0xff54)
sfr PWMCFG = 0xf1; sfr PWMCR = 0xf5; sfr PWMIF = 0xf6; sfr PWMFDCR = 0xf7;
sfr TH2 = 0xD6; sfr TL2 = 0xD7; sfr IE2 = 0xAF; sfr INT_CLKO = 0x8F; sfr AUXR = 0x8E; sfr AUXR1 = 0xA2; sfr P_SW1 = 0xA2; sfr P_SW2 = 0xBA;
sfr PIN_SW2 =0xBA; sfr S2CON = 0x9A; sfr S2BUF = 0x9B;
sfr P4 = 0xC0; sfr P5 = 0xC8; sfr P6 = 0xE8; sfr P7 = 0xF8;
sfr P1M1 = 0x91; sfr P1M0 = 0x92; sfr P0M1 = 0x93; sfr P0M0 = 0x94; sfr P2M1 = 0x95; sfr P2M0 = 0x96; sfr P3M1 = 0xB1; sfr P3M0 = 0xB2; sfr P4M1 = 0xB3; sfr P4M0 = 0xB4; sfr P5M1 = 0xC9; sfr P5M0 = 0xCA; sfr P6M1 = 0xCB; sfr P6M0 = 0xCC; sfr P7M1 = 0xE1; sfr P7M0 = 0xE2;
sbit P00 = P0^0; sbit P01 = P0^1; sbit P02 = P0^2; sbit P03 = P0^3; sbit P04 = P0^4; sbit P05 = P0^5; sbit P06 = P0^6; sbit P07 = P0^7; sbit P10 = P1^0; sbit P11 = P1^1; sbit P12 = P1^2; sbit P13 = P1^3; sbit P14 = P1^4; sbit P15 = P1^5; sbit P16 = P1^6; sbit P17 = P1^7; sbit P20 = P2^0; sbit P21 = P2^1;
//PxM1.n,PxM0.n // =00--->Standard, =10--->pure input, 01--->push-pull 11--->open drain
相关推荐: