亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? softuart.c

?? c8051f單片機以太網測控資料
?? C
?? 第 1 頁 / 共 2 頁
字號:
//------------------------------------------------------------------------------------
//
// Copyright 2001	Cygnal Integrated Products, Inc.
//
// FILE NAME		: softuart.c
// TARGET DEVICE	: C8051F02x
// CREATED ON		: 06/07/04
// CREATED BY		: JS
//
// Software UART program, using PCA as baud rate source.
// PCA module 0 is used as receive baud rate source and START detector.  For START
// detection, module 0 is configured in negative-edge capture mode.  For all other
// SW_UART operations, module 0 is configured as a software timer.  Module match
// interrupts are used to generate the baud rate.  Module 1 generates the transmit
// baud rate in software timer mode. 
// Code assumes an external crystal is attached between the XTAL1 and XTAL2 pins.
// The frequency of the external crystal should be defined in the SYSCLK constant.
// 
// INITIALIZATION PROCEDURE:
// 1) Define SYSCLK according to external crystal frequency.
// 2) Define desired BAUD_RATE.
// 3) Call SW_UART_INIT().
// 4) Set SREN to enable SW_UART receiver.
// 5) Set SES only if user-level interrupt support is desired.
// 6) Call SW_UART_ENABLE().
//
// TO TRANSMIT:
// 1) Poll STXBSY for zero.
// 2) Write data to TDR.
// 3) Set CCF1 to initiate transmit.
// 4) STI will be set upon transmit completion.  An IE7 interrupt is generated if 
//    user-level interrupts are enabled.
//
// TO RECEIVE:
// 1) If in polled mode, poll SRI.  If in interrupt mode, check SRI in IE7 Interrupt
//    Service Routine.
// 2) Read data from RDR.
// 
// Test code is included, for both polled and interrupt mode.  Test code assumes
// the HW_UART pins and SW_UART pins are connected externally:
// P0.0 (HW_UART TX) ->  P2.2 (SW_UART RX)
// P0.1 (HW_UART RX) ->  P2.7 (SW_UART TX)
// 
// To use the test code in polled mode, comment out the call to the INTERRUPT_TEST()
// at the bottom of the main routine, and uncomment the call to POLLED_TEST().  To 
// test the interrupt mode, comment out the POLLED_TEST() call and uncomment the
// INTERRUPT_TEST() call.
//
// The test routines configure the HW_UART to operate with Timer 1 as the baud rate
// source.  The Timer 1 preload values are auto-calculated from the SYSCLK and BAUD_RATE
// constants.
//
//-----------------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------------
#include <c8051f020.h>								// SFR declarations

//-----------------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------------

#define	BAUD_RATE		38400						// User-definable SW_UART baud rate
#define	SYSCLK			11059200					// System clock derived from 11.0592MHz XTL

#define 	TIME_COUNT		SYSCLK/BAUD_RATE/4	// Number of PCA counts for one bit-time.
															// (PCA configured to count SYSCLK/4)

#define	TH_TIME_COUNT	TIME_COUNT*3/2			// 3/2 bit-time, for use after receiving
															// a START bit.  RX should be LOW for one
															// bit-time after the edge of the START,
															// and the first bit sample starts in the
															// middle of the next bit-time.

#define	HW_TIME_COUNT	SYSCLK/BAUD_RATE/16 	// Time count for HW_UART baud rate
															// generation.  Auto-calculated from the
															// SYSCLK and BAUD_RATE constants defined
															// above.

//-----------------------------------------------------------------------------------
//Global VARIABLES
//-----------------------------------------------------------------------------------

bit	SRI;												// SW_UART Receive Complete Indicator
bit	STI;												// SW_UART Transmit Complete Indicator
bit	STXBSY;											// SW_UART TX Busy flag
bit 	SREN;												// SW_UART RX Enable
bit	SES;												// SW_UART User-level Interrupt Support Enable

sbit	SW_RX = P2^2;  								// SW_UART Receive pin
sbit	SW_TX = P2^7;  								// SW_UART Transmit pin

char 	TDR;												// SW_UART TX Data Register
char 	RDR;												// SW_UART RX Data Register (latch)

// Test Variables
char k, m;												// Test indices.
char idata SW_BUF[20];								// SW_UART test receive buffer.

bit	HW_DONE;											// HW transfer complete flag (15 characters
															// transmitted.)
bit	SW_DONE;											// SW transfer complete flag (15 characters
															// transmitted.)

//------------------------------------------------------------------------------------
// Function PROTOTYPES
//------------------------------------------------------------------------------------

void	SW_UART_INIT();								// SW_UART initialization routine
void	SW_UART_ENABLE();								// SW_UART enable routine
void	PCA_ISR();										// SW_UART interrupt service routine
void 	INTERRUPT_TEST(void);						// SW_UART test routine using interrupt mode
void 	POLLED_TEST(void);							// SW_UART test routine using polled mode
void 	USER_ISR(void);								// SW_UART test interrupt service routine
void 	HWU_INIT(void);								// HW_UART initialization and setup routine
void	HW_UART_ISR(void);							// HW_UART interrupt service routine						
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
// - Disables Watchdog Timer
// - Configures external crystal; switches SYSCLK to external crystal when stable.
// - Configures crossbar and ports.
// - Initializes and enables SW_UART.
// - Calls Test Routines.
//
void MAIN (void){
//	int delay;											// Delay counter.
    unsigned int i;
//OSCXCN = 0x66;										// Enable external crystal	
	WDTCN = 0xDE;										// disable watchdog timer
	WDTCN = 0xAD;

	// Port Setup
	XBR0 = 0x0f;										// HW_UART routed to pins P0.0 and P0.1;
															// CEX0 routed to pin P0.2.
	XBR2 = 0x44; 										// Enable crossbar, pull-ups enabled.

    P1MDIN = 0x00;										// P0.0 (HW TX), and P0.3 (SW TX)
	P2MDOUT |= 0X80;														// configured for push-pull output.
    P0MDOUT |= 0X01;
  OSCXCN = 0x67;                      // start external oscillator with
                                       // 11.0592MHz crystal

   for (i=0; i < 256; i++) ;           // XTLVLD blanking interval (>1ms)

   while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle

   OSCICN = 0x88;                      // select external oscillator as SYSCLK
                                       // source and enable missing clock
                                       // detector
//	POLLED_TEST();										// Call Polled mode SW_UART test routine.
	INTERRUPT_TEST();									// Call Interrupt mode SW_UART test routine.

	while(1);											// Spin forever
}


//------------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------
// INTERRUPT_TEST: SW_UART Interrupt Mode Test
// Test code to transmit and receive 15 characters to/from the HW_UART (in interrupt
// mode), with SW_UART in interrupt mode.
// - Initializes and enables the SW_UART & HW_UART
// - Clears all test variables & counters
// - Transfers 15 characters from HW to SW_UART, and 15 characters from SW to HW_UART,
//   simultaneously. 
//
void INTERRUPT_TEST(void){

	SW_UART_INIT();									// Initialize SW_UART
	SW_UART_ENABLE();									// Enable SW_UART
	SREN = 1;											// Enable SW_UART Receiver
	SES = 1;												// User-level interrupt support enabled.

	HWU_INIT();											// Configure HW_UART for testing routine.
	k=m=0;												// Clear user ISR counters.
	
	HW_DONE=0;											// Clear transfer complete indicators
	SW_DONE=0;											// 

	IE |= 0x10;											// Enable HW_UART interrupts
	STI=1;												// Indicate transmit complete to initiate
															// next transfer.
	EIE2 |= 0x20;										// Start SW_TX by enabling
	P3IF |= 0x80;									// and forcing an IE7 interrupt
	
   TI0 = 1;                                   // Initiate a HW_UART transmit
                                             // by forcing TX interrupt.

	while(!(HW_DONE&SW_DONE));						// Wait for transfers to finish.
}

//---------------------------------------------------------------------------------------
// POLLED_TEST: SW_UART Polled Mode Test
// Test code to transmit and receive 15 characters to/from the HW_UART, with SW_UART
// in polled mode.
// - Initializes and enables the SW_UART & HW_UART
// - Clears all test variables & counters
// - Sends 15 characters from the HW_UART to be received by SW_UART.
// - Sends 15 characters from the SW_UART to be received by the HW_UART.
//
void POLLED_TEST(void){

	SW_UART_INIT();									// Initialize SW_UART
	SW_UART_ENABLE();									// Enable SW_UART
	SREN = 1;											// Enable SW_UART Receiver
	SES=0;												// Disable user-level interrupt support.

	HWU_INIT();											// Configure HW_UART for testing routine.
	k=m=0;												// Clear test counter variables.
	HW_DONE=0;											// Clear transfer complete indicators
	SW_DONE=0;											//
	IE |= 0x10;											// Enable HW_UART interrupts.

   TI0 = 1;                                   // Initiate a HW_UART transmit
                                             // by forcing TX interrupt.

	// Receive 15 characters with SW_UART; transmit with HW_UART.
	while(SREN){                              // Run while SW_UART Receiver is
                                             // enabled.	
		if (SRI){										// If Receive Complete:
			SRI = 0;										// Clear receive flag.
			SW_BUF[k++] = RDR;						// Read receive buffer.
			if (k==15){									// If 15 characters have been received:
				SREN = 0;								// Disable SW_UART Receiver.
			}												// Indicate 15 characters received.
		}
	}

	// Transmit 15 characters with SW_UART; receive with HW_UART.
	while(STXBSY);										// Poll Busy flag.
   STXBSY = 1;                               // Claim SW_UART Transmitter
	TDR=m++;												// Load TX data.
	CCF1=1;												// Initiate first SW_UART TX
															// by forcing a PCA module 1 interrupt.
	while(!SW_DONE){									// SW_UART transmitting here; HW_UART receiving.

		if (STI){										// If Transmit Complete:
			STI = 0;										// Clear transmit flag.
			if (m<16){									// Transmit 15 characters.
				STXBSY = 1;                      // Claim SW_UART Transmitter.
            TDR = m++;								// Transmit, increment variable.
				CCF1 = 1;								// Force module 1 interrupt to initiate TX.
			}
         else											// If this is 15th character,
				SW_DONE=1;								// Indicate last character transmitted.
		}
	}
}

//------------------------------------------------------------------------------------------
// HWU_INIT: HW_UART Initialization Routine
// Sets up HW_UART for use in SW_UART testing.
// - HW_UART in mode 1
// - Timer 1 used as baud rate source, clocked by SYSCLK.
//
void HWU_INIT(void) {

	PCON |= 0x80;										// SMOD=1 (HW_UART uses Timer 1 overflow
															// with no divide down).

	TMOD = 0x20;										// Configure Timer 1 for use by HW_UART
	CKCON |= 0x10;										// Timer 1 derived from SYSCLK
	TH1 = -HW_TIME_COUNT;							// Timer 1 initial value
	TL1 = -HW_TIME_COUNT;							// Timer 1 reload value

	TR1 = 1;    										// Start Timer 1

	RI0=0;													// Clear HW_UART receive and transmit
	TI0=0;													// complete indicators.

	SCON0 = 0x50;										// Configure HW_UART for mode 1, receiver enabled.
}
//------------------------------------------------------------------------------------------
// SW_UART_INIT: SW_UART initialization routine
// Prepares SW_UART for use.
// - Configures PCA: Module 0 in negative capture mode; module 1 in software 
//   	timer mode; PCA time base = SYSCLK/4; PCA interrupt disabled; PCA counter
//		disabled.
// - Clears pending PCA module 0 and 1 interrupts
// - Resets TX and RX state variables
//
void	SW_UART_INIT(void){

	PCA0CPM0 = 0x10;									// Module 0 in negative capture mode; module
															// 0 interrupt disabled.

	PCA0CPM1 = 0x48; 									// Module 1 in software timer mode; module
															// 1 interrupt disabled.	

	PCA0CN = 0;											// Leave PCA disabled
	PCA0MD = 0x02;										// PCA timebase = SYSCLK/4; PCA counter
															// interrupt disabled.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人av在线网| 黄色资源网久久资源365| 亚洲最大色网站| 国产亲近乱来精品视频| 久久久.com| 国产精品第四页| 亚洲欧美日韩中文播放| 一区二区三区日韩在线观看| 亚洲免费三区一区二区| 亚洲你懂的在线视频| 亚洲国产精品天堂| 日韩va亚洲va欧美va久久| 天天操天天干天天综合网| 奇米精品一区二区三区在线观看| 蜜桃av一区二区| 国产精品18久久久久久久久久久久| 国产一区不卡视频| 不卡免费追剧大全电视剧网站| youjizz国产精品| 欧美在线不卡一区| 欧美一区二区三区在线| 亚洲精品一区二区三区福利| 中文子幕无线码一区tr| 亚洲一区二区三区爽爽爽爽爽| 日本成人在线一区| 国产69精品久久久久777| 91在线免费播放| 欧美日本一区二区在线观看| 久久亚洲一区二区三区四区| 成人免费在线视频观看| 午夜精品久久久久久久99水蜜桃| 国产精品中文字幕欧美| 在线观看国产日韩| 2021中文字幕一区亚洲| 亚洲美女区一区| 国内精品视频666| 欧美亚洲一区三区| 久久久不卡影院| 日韩电影网1区2区| 91丝袜高跟美女视频| 26uuu国产日韩综合| 亚洲男同1069视频| 国产成人一区二区精品非洲| 欧美三区免费完整视频在线观看| 久久色在线观看| 偷拍亚洲欧洲综合| 不卡区在线中文字幕| 日韩欧美黄色影院| 一个色在线综合| 不卡的av在线播放| 久久久国产精华| 美女网站在线免费欧美精品| 欧美性猛片aaaaaaa做受| 国产精品不卡在线观看| 激情成人午夜视频| 在线电影一区二区三区| 亚洲乱码国产乱码精品精可以看 | 国产精品久久影院| 免费成人结看片| 欧美日韩精品免费| 亚洲男女毛片无遮挡| 成人免费看片app下载| 精品国产乱码久久久久久夜甘婷婷 | 91免费观看在线| 日本一二三不卡| 国产成人精品免费网站| 精品国精品自拍自在线| 日韩高清在线观看| 欧美一区二区不卡视频| 午夜精品福利一区二区蜜股av| 欧洲av在线精品| 一区二区在线观看免费| 91麻豆精品在线观看| 亚洲人成在线播放网站岛国| 国产成人在线电影| 国产精品网站在线播放| aaa欧美日韩| 一区二区三区四区国产精品| 色婷婷av一区二区三区软件| 亚洲美女精品一区| 欧美性感一区二区三区| 午夜成人免费视频| 欧洲色大大久久| 日韩精品三区四区| 欧美一区二区高清| 麻豆精品一区二区综合av| 欧美精品一区二区三区很污很色的| 狠狠色综合日日| 亚洲国产成人自拍| 日本精品视频一区二区三区| 夜色激情一区二区| 欧美一区二区三区小说| 国产精品18久久久久久久久| 欧美国产禁国产网站cc| 欧美专区亚洲专区| 亚洲国产一区在线观看| 日韩欧美成人激情| 成人动漫av在线| 亚洲男人的天堂av| 日韩精品一区二区三区三区免费 | 日韩国产精品大片| 日韩免费看的电影| 国产九色sp调教91| 亚洲国产综合视频在线观看| 欧美白人最猛性xxxxx69交| 福利视频网站一区二区三区| 夜夜嗨av一区二区三区中文字幕| 欧美高清精品3d| 国产成人精品网址| 午夜免费欧美电影| 国产精品美女久久久久久| 日本高清不卡一区| 国产一区二区在线影院| 亚洲日韩欧美一区二区在线| 欧美一区二区三区免费大片| 不卡av电影在线播放| 蜜乳av一区二区| 亚洲精品欧美专区| 久久久精品日韩欧美| 欧美美女一区二区在线观看| 成人黄色网址在线观看| 久久66热偷产精品| 亚洲一区二区三区在线| 国产精品麻豆视频| ww久久中文字幕| 制服丝袜一区二区三区| 成人免费av在线| 久久电影网电视剧免费观看| 亚洲一线二线三线视频| 国产精品妹子av| 久久久不卡网国产精品一区| 91精品国产一区二区三区蜜臀| 91国产丝袜在线播放| 成人涩涩免费视频| 国产高清久久久| 免费不卡在线观看| 日本一道高清亚洲日美韩| 亚洲一区二区三区四区在线观看 | 欧美日韩一区二区三区在线| 成人午夜伦理影院| 久久99精品久久久久久动态图| 午夜日韩在线观看| 一区二区三区国产豹纹内裤在线| 国产精品日产欧美久久久久| 久久综合狠狠综合久久综合88| 日韩精品在线一区二区| 欧美日韩精品综合在线| 欧美午夜宅男影院| 91国偷自产一区二区使用方法| 91亚洲精品乱码久久久久久蜜桃| 岛国精品在线观看| 高清视频一区二区| 成人免费精品视频| 99国产精品一区| 日本丰满少妇一区二区三区| 色拍拍在线精品视频8848| 91丨九色丨黑人外教| 色狠狠综合天天综合综合| 色欲综合视频天天天| 欧美性一级生活| 欧美视频一区二| 日韩一二三区视频| 久久精品夜夜夜夜久久| 中文字幕中文乱码欧美一区二区 | 免费观看日韩av| 蜜桃视频免费观看一区| 韩国欧美国产1区| 成人中文字幕合集| 色呦呦国产精品| 欧美日韩国产a| 久久久久久久久蜜桃| 成人欧美一区二区三区1314| 一区二区三区自拍| 日本大胆欧美人术艺术动态| 国产在线不卡一区| av日韩在线网站| 欧美性猛交xxxx乱大交退制版| 日韩欧美色电影| 中文字幕在线不卡| 视频在线观看91| 风间由美一区二区av101| 在线视频欧美区| 精品久久一区二区三区| 亚洲欧美另类小说视频| 青娱乐精品在线视频| 懂色av中文一区二区三区| 欧美日韩一区不卡| 国产欧美一区二区三区沐欲 | 欧美成人国产一区二区| 国产精品网站一区| 日韩av成人高清| 91麻豆免费看片| 欧美精品一区二区三区蜜臀| 亚洲综合久久av| 国产成人午夜99999| 欧美精品 国产精品| 亚洲欧洲无码一区二区三区| 奇米色一区二区| 91国偷自产一区二区使用方法| 2024国产精品|