C51源程序集合
包括以下目录源码
├─AD-MSP430f149D
├─ADC8535
├─bin
├─c51源程序
├─c51源程序锦集
├─ct2Timer
├─
源代码在线查看: c51的单片机底层串口程序.txt
用【 小 | 中 | 大 】字体浏览
C51编程:快帮帮我呀 [lsp9672] [50次] 01-12-28 上午 09:23:23
各位大虾好,小生最近急需要使用一个C51的单片机底层串口程序,对这个串口程序的要求
是一个独立的模块。因为我要把这个串口程序襄入到我的程序里面,通过PC机来监视程序运
行中一些标志和变量的变化,不知道在那里能找到这样的串口程序呢???
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
#include
#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 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();
}
}
你有与这个程序配套的PC端的程序吗?? [lsp9672] [2次] 01-12-28 下午 12:01:08
先谢谢你,你有与这个程序配套的PC端的程序吗??我在PC端怎么观察我要监视的对象
呢??
点击这里回复这篇贴子>>
_____________________________________________________________________________
Copyright?,C51BBS论坛 2000-2002