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

📄 scom.c

📁 51单片机控制液晶显示器6963c
💻 C
字号:
#include "SwitchMCU.h"
#ifdef AT89C52
#include <reg51.h>//89c51,89c52
#endif
#ifdef W77E58
#include "77e58.h"	//77E58
#endif
#include <string.h>
#include "config.h"
#include "SComFun.h"
#include "24c64.h"
#include "ReadFPGA.h"
#include "DS1307.h"
#include "my_types.h"
#include "TL16C554A.h"

#define XTAL     11059200L
#define baudrate 9600L    

#define POWER	P0_3
#define SKEY1   P2_0
#define LOCK373 P3_5

bit  onTime = false ;
uint timeCount = 0 ;

void Delay(int cnt)
{
	int idata i, num ;
	
	for(i=0;i<cnt;i++)
	{
		num = 0 ;
		while(num<1000) 
		{
			num++;	
		}
	}	
}

#ifdef AT89C52
void InitSCom(void)		//串口初试化
{
	EA 	 = 0 	;  		//关中断
	TI   = 0	;		//清除发送中断标志位
	RI   = 0    ;		//清除接收中断标志位
	TR1  = 0    ;		//关定时器1
	TMOD = 0x20 ;		//定时器1方式2
	TH1  = 0xFD ;		//9600波特11.0592 MHz
	SCON = 0x50 ;		//允许接收
	TR1  = 1	;		//开定时器1
	ES   = 1 	;		//开串口中断
	EA 	 = 1	;		//开中断
}

void InitSCom_InHelloProgram(void)
{
	EA = 0;
	RI = 0 ;
	PCON |= 0x80;			    /* 0x80=SMOD: set serial baudrate doubler */
	TR1 = 0;			    	/* stop timer 1 */
	ET1 = 0;			    	/* disable timer 1 interrupt */
    SCON  = 0x50;		        /* SCON: mode 1, 8-bit UART, enable rcvr      */
    TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload        */
    TH1   = 221;                /* TH1:  reload value for 1200 baud @ 16MHz   */
	#define XTAL     11059200L
	#define baudrate 9600L    
	TH1 = (unsigned char) (256 - (XTAL / (16L * 12L * baudrate)));
	TR1   = 1;                  /* TR1:  timer 1 run                          */
    TI    = 1;                  /* TI:   set TI to send first char of UART    */
	ES = 1 ;
	EA = 1 ;
}
#endif

#ifdef W77E58
void Init() {
  P0 = 0xff;
  P1 = 0xff;
  P2 = 0xff;
  P3 = 0xff;
}

void Init_Mcu(void)
{
  PMR=0x41;  // 4clocks/machinecycle,switch disable
             // ALE enable and internal SRAM enable
             // oscilator enable
  PCON=0xb0; // this is to set SM0 to be UART mode setting
             // double the serial rate,SMOD=1
             // GF0 and GF1 can be used as other purpose
  DPS=0x00;  // DPTR will be selected here,DPTR selected here
  TCON=0x00; /* external interrupt should be set to low level trigger and T0 and T1 should stop now*/
  TMOD=0x21; /* T1  should be set autoload 8 bits timer mode to act as baudrate generator*/
             /* T0 should act as 16 bits timer*/
  TH1 = (unsigned char) (256 - (XTAL / (16L * 12L * baudrate)));
  CKCON=0xc1;/* to set Timer0 and Timer1 clock*/
             /* Clock of Timer0 ,Timer1 and Timer2 is divided by 12,MOVX strecash occupy 3(default) machine cycle watch dog time out 2(26)+512   */
  SCON0=0x5c;/* receive and transmitter will be enbled*/
  SCON1=0x5c;/* serial port1 and port0 will act in Mode1
                 the baudrate will be varible*/
             // transimitter enable now
  IE=0x52;   /* this is to set interrupt enable*/
             // Enabled: T0,S0 and S1,T2
             // disble: T1,EXT0 and EXT1
  WDCON=0x80;// double serial1 baudrate,disable wathcdog reset
  IP=0x10;   /* this is to set interrupt prioprity*/
             // S0 will be high and else will be low
  EIE=0x00;  // disable watchdog interrupt and extern2-5 interrupt
  EIP=0x00;  // all extended external interrupt disabled above
  T2CON=0x00;// this is to decide which Timer will act as
             // baudrater for serial port0:TIMER1
             // Timer2 work in reload mode

  T2MOD=0xf0;// EXTN2,3,4,5 flag auto clear,T2 down counter disable
  EA=0;	     /* disable all interrupt now ,should be opened later*/
             //there is another useful register can be used: STATUS,pay attention for it
}
#endif

#if(0)
void TryPutData(void)	//回送串口接收到的数据函数
{
	if(reFull)
	{
		reFull = false ;
		reBuff[reNum] = 0 ;
		strcpy(trBuff, reBuff) ;
		PutSComData(trBuff, reNum) ;
		reNum = 0 ;
		reBuff[reNum] = 0 ;
	}
}
#endif

//char timesOn = 0 ;
int timesOn = 0 ;

void Timer(void) interrupt 1 using 2
{
	TH0 = -(1200/256) ;
	TL0 = -(1200%256) ;
	
	#if(0)
	if(timeCount < 1000)
	{
		timeCount++ ;	
	}
	else
	{
		timeCount = 0 ;
	}
	#endif

	if(!SKEY1)
	{
		timesOn++ ;
		if(timesOn >= 5000)
		{
			onTime = true ;
			timesOn = 0 ;
		}
	}
	else
	{
		timesOn = 0 ;
		onTime = false ;
	}
}

int main(void)
{
	Delay(10);
	#ifdef AT89C52
	InitSCom() ;		//串口初试化
	//InitSCom_InHelloProgram() ;
	#endif
	#ifdef W77E58
  	Init() ;
  	Init_Mcu() ;
  	ES = 1 ;
  	ES1 = 1 ;
  	REN = 1 ;
  	REN_1 = 1 ;
	EA = 1 ;
	TR1 = 1 ;
	TR0 = 1 ;			//开启定时器0
	ET0 = 1 ;			//开中断
	TH0 = -(1200/256) ;
	TL0 = -(1200%256) ;
  	SioEnd = 1 ;
	LOCK373 = 1 ;
	POWER = 0 ;
	Delay(10) ;
	LOCK373 = 0 ;
	timesOn = 0 ;
	onTime = false ;
  	#endif
	InitDS1307() ;		//初始化DS1307
	TL16C554A_init(UART1, 9600, FIFO_ENABLE); //EX_COM1 初始化
	TL16C554A_init(UART2, 9600, FIFO_ENABLE); //EX_COM2 初始化
	TL16C554A_init(UART3, 9600, FIFO_ENABLE); //EX_COM3 初始化
	TL16C554A_init(UART4, 9600, FIFO_ENABLE); //EX_COM4 初始化
	Delay(10);
	
	while(true)
	{
		#if(1)
		if(reFull)
		{
			ProcessCmd() ;	
			reFull = false ;
		}
		#endif
		if(onTime)
		{
			LOCK373 = 1 ;
			POWER = 1 ;
			Delay(10) ;
			LOCK373 = 0 ;
			onTime = false ; 
		}
	}
	
	return 0 ;
}

⌨️ 快捷键说明

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