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

📄 mainloop.c

📁 interface usb microcontroller with pc
💻 C
字号:
//*************************************************************************
//
//                  P H I L I P S   P R O P R I E T A R Y
//
//           COPYRIGHT (c)   2003 BY PHILIPS SEMICONDUCTORS
//                     --  ALL RIGHTS RESERVED  --
//
// File Name:	mainloop.c
// Created:		April 16, 2004
// Modified:	Handoko (Hans) Chendra
// Revision: 	1.00
// 
//*************************************************************************

#include <REG51RX.H>
#include "uart.h"

void main(void)
{
	unsigned int ch;
	unsigned int uart_method; // 0 = polling, 1 = interrupt

   uart_method = 0; // polling
   
   if (uart_method == 1) // check if using the interrupt driven								  
		IE = 0x84; // enable the microcontroller interrupt bit and external 1
	
	Uart_Reset(); // reset UART 
		
	// init for channel A
	Uart_Write(CRA,  0xB5);  // set MR pointer to MR0, enable Tx and Rx
	Uart_Write(MRA,  0x00);  // normal baud rate
	Uart_Write(MRA,  0x13);  // RxRDY, char, no parity, even, 8
   Uart_Write(MRA,  0x07);  // normal channel mode, 1 stop bit
   Uart_write(CSRA, 0xBB);  // 9600 bps for Tx and Rx 
		
	// init for channel B
	Uart_Write(CRB,  0xB5);  // set MR pointer to MR0, enable Tx and Rx
	Uart_Write(MRB,  0x00);  // normal baud rate
	Uart_Write(MRB,  0x13);  // RxRDY, char, no parity, even, 8
   Uart_Write(MRB,  0x07);  // normal channel mode, 1 stop bit	
   Uart_write(CSRB, 0xBB);  // 9600 bps for Tx and Rx 

	// init for both channels
	Uart_Write(ACR,  0x00);  // BRG set 1
	   
	if (uart_method == 1) // check if using the interrupt driven
		Uart_Write(IMR, 0x02);  // enable RxRDY interrupt

	while (1)		
   {
		// polling method - read regularly
      if (Uart_Read(SRA) & 0x01) { // check if a char has been received in Rx FIFO
			ch = Uart_Read(RHRA);  // read a char from the receive holding register
  			Uart_Write(THRA, ch);  // send a char to the transmit holding register
   	}   	
   } // end while 1
}

void UART_Interrupt(void) interrupt 2  // External interrupt 1 - P3.3
{
	unsigned int ch;
		
   if (Uart_Read(SRA) & 0x01) {  // check if a char has been received in Rx FIFO
		ch = Uart_Read(RHRA);  // read a char from the receive holding register
  		Uart_Write(THRA, ch);  // send a char to the transmit holding register
  	}
}

⌨️ 快捷键说明

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