⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hardwarec.c

📁 在89C51上操作小型LCD,显示汉字,字符和图案,字库放在EEPROM
💻 C
字号:
#include <reg51.h>
#include "..\..\typedef.h"
#include "..\osh.h"

#define DEBUG		0
#define Timer0Run(var)	{TR0 =var?1:0;}

#define CPUFREQ		11059200
#define SAMPLEFREQ		150
#define SAMPLETIME	(CPUFREQ/12/SAMPLEFREQ)  
#define UARTBAUDRATE 9600
U8 SystemNum,DelayTime;
void Rs232Init(void);

void Timer0Init(void)
{
	TMOD |=0x01;
	TH0	=-(SAMPLETIME/256);
	TL0 =-(SAMPLETIME%256);
	ET0=1;
}
void timer0(void) interrupt 1 using 2
{
	TH0	=-(SAMPLETIME/256);
	TL0 =-(SAMPLETIME%256);
	OS.Flag.Timer32ms=1;
}
void SystemInit(void)
{
	P0=0xff;
	P1=0xff;
	P2=0xff;
	P3=0xff;
//	TxDataFlow.uint=-1;
	Timer0Init();
	Timer0Run(1);
	Rs232Init();
	ET1=0;
	EA=1;
//	Timer1Run(0);
}
void Rs232Init(void) 
{
 
   TCON &= 0x3F;                     /* clear run & interrupt flags        */
   TMOD &= 0x0F;                     /* flush existing Timer 1 setup       */
   TMOD |= 0x20;                     /* flush existing Timer 1 setup       */

   SCON = 0x50;                     /* flush existing Timer 1 setup        */
   PCON |= 0x00;                       
   TH1 = TL1 = (unsigned char)( 256-((CPUFREQ/6)/32)/UARTBAUDRATE);  //设置波特率发生器定时器
   TR1 = 1;                        /* start the timer                    */
   TI  = 1;
   
}

void Timer1(void) interrupt 3 using 3{
/*
	U8 data temp2;
	if(Tx0) SetBit(P2,7);
	else	ClrBit(P2,7);
	temp2=Tx0^Tx4; 				
	TxDataFlow.uint >>=1;  
	TxDataFlow.uchar[0]=temp2;
*/	
}
U8 KeyScan0(void)
{
	U8 ch;
	P0 |=0xe0;
	ClrBit(P0,6);
	ClrBit(P0,7);
	ch=P2&0xf0;
	if(ch){
	    ch >>=4;
		ch |=0x20;//P0&0xe0;
		return (ch);
	}	
	P0 |=0xe0;
	ClrBit(P0,5);
	ClrBit(P0,7);
	ch=P2&0xf0;
	if(ch){
	    ch >>=4;
		ch |=0x40;//P0&0xe0;
		return (ch);
	}	
	P0 |=0xe0;
	ClrBit(P0,6);
	ClrBit(P0,5);
	ch=P2&0xf0;
	if(ch){
	    ch >>=4;
		ch |= 0x80;
		return (ch);
	}	
}
void SetKeyOut(void)
{
	P0 |=0xe0;
}
U8 KeyInput(void)
{
	return(P2&0xf0);
}
#if DEBUG==1
void PutChar(U8 i)
{
	SBUF=i;
	while(TI==0);
	TI=0;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -