?? c51的單片機(jī)底層串口程序.txt
字號(hào):
用【 小 | 中 | 大 】字體瀏覽
C51編程:快幫幫我呀 [lsp9672] [50次] 01-12-28 上午 09:23:23
各位大蝦好,小生最近急需要使用一個(gè)C51的單片機(jī)底層串口程序,對(duì)這個(gè)串口程序的要求
是一個(gè)獨(dú)立的模塊。因?yàn)槲乙堰@個(gè)串口程序襄入到我的程序里面,通過(guò)PC機(jī)來(lái)監(jiān)視程序運(yùn)
行中一些標(biāo)志和變量的變化,不知道在那里能找到這樣的串口程序呢???
too easy [程咬金] [36次] 01-12-28 上午 11:13:57
/**
* Program Name: ser_int.c
*
* Creation Date: 10.25.2001
*
* Programmers: Liu Limin
*
* Modifications:
*
* Comments: ...
*
* Copyright (c) 2001 by CoreLogic Communication, INC.
*
**/
#include <reg52.h>
#include <stdio.h>
#include "ser_int.h"
void SerInitialize()
{
SerFlags = 0;
FlagTransIdle = 1;
FlagCvtInCR = 1; // want to turn CRs into LFs
RR_iHead = RR_iTail = RR_cLev = RR_cMax = 0;
TR_iHead = TR_iTail = TR_cLev = TR_cMax = 0;
UnGotCh = -1;
//
//--- set up Timer 1 to produce serial rate
T2CON = 0x30;
// T2MOD = 0x00;
SCON = 0x50;
PCON |= 0x00;
RCAP2H = 0xFF;
RCAP2L = 0xDC;
TR2 = 1;
// ET2 = 1;
ES = 1;
EA = 1;
}
//---------------------------------------------------------------------------
// Serial interrupt handler
void SerInt() interrupt 4 using 1
{
if(RI) {
if(RR_cLev<INRINGSIZE) {
RRing[RR_iHead] = SBUF;
RR_iHead++;
RR_cLev++;
if(RR_iHead==INRINGSIZE) RR_iHead = 0;
}
RI = 0;
}
if(TI) {
if(TR_cLev) {
SBUF = TRing[TR_iTail];
TR_cLev--;
TR_iTail++;
if(TR_iTail==OUTRINGSIZE) TR_iTail = 0;
} else FlagTransIdle = 1;
TI = 0;
}
}
//---------------------------------------------------------------------------
// Send character to .....
void putch(unsigned char TransChar)
{
putc(TransChar);
if(TransChar=='\n') putc('\r');
}
unsigned char putc(unsigned char TransChar)
{
while(TR_cLev>=OUTRINGSIZE);
ES = 0;
TRing[TR_iHead] = TransChar;
TR_iHead++;
TR_cLev++;
if(TR_iHead==OUTRINGSIZE) TR_iHead = 0;
if(FlagTransIdle) {
FlagTransIdle = 0;
TI = 1;
}
ES = 1;
return(TransChar);
}
unsigned char chkch()
{
return(RR_cLev);
}
//---------------------------------------------------------------------------
// Wait for the serial transmitter to go idle
void SerWaitOutDone()
{
while(TR_cLev);
while(!FlagTransIdle);
}
//---------------------------------------------------------------------------
// Flush the input buffer
// Returns number of chars flushed
void SerFlushIn()
{
ES = 0;
RR_iTail = 0;
RR_iHead = 0;
RR_cLev = 0;
ES = 1;
}
//---------------------------------------------------------------------------
// Get character from ....
char getch()
{
int RetVal;
ES = 0;
if(RR_cLev) {
RetVal = RRing[RR_iTail];
if(RetVal=='\r') RetVal = '\n';
RR_iTail++;
RR_cLev--;
if(RR_iTail==INRINGSIZE) RR_iTail = 0;
} else RetVal = -1;
ES = 1;
return(RetVal);
}
//---------------------------------------------------------------------------
// Send string to ........
// putstr(char *pString);
void putstr(unsigned char *pstring)
{
while(*pstring) {
putch(*pstring);
pstring++;
}
}
void main(void)
{
unsigned int ch = 0;
// unsigned char char_cnt = 0;
SerFlushIn();
SerInitialize();
for(;;) {
if(chkch()) {
ch = getch();
}
if(ch) {
putch(ch);
// char_cnt ++;
}
/* if(!(char_cnt % 40)) {
char_cnt = 0;
putstr("\n\r");
}
*/
// for(ch = 0; ch < 0x3fff; ch ++);
// putstr("Calling Number : 5551212 !!!\n\r");
//SerWaitOutDone();
}
}
你有與這個(gè)程序配套的PC端的程序嗎?? [lsp9672] [2次] 01-12-28 下午 12:01:08
先謝謝你,你有與這個(gè)程序配套的PC端的程序嗎??我在PC端怎么觀察我要監(jiān)視的對(duì)象
呢??
點(diǎn)擊這里回復(fù)這篇貼子>>
_____________________________________________________________________________
Copyright?,C51BBS論壇 2000-2002
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -