菜鸟第六贴 串口收发
/********************************************************************************
** daxinganling@hotmail.com
**Filename : Receive And Send Uart6 in interrupt mode
**Abstract : This file implements main function.
**APIlib : NEC78K0SKX1+.lib V1.70
**
**Device : uPD78F9234
**
**Compiler : NEC/CC78K0
**
*******************************************************************************
*/
#pragma interrupt INTSR6 MD_INTSR6
#pragma interrupt INTST6 MD_INTST6
#include "macrodriver.h"
#include "system.h"
/*
*******************************************************************************
**MacroDefine
*******************************************************************************
*/
/*
**---------------------------------------------------------------------------
**
**Abstract:
** This function implements main function.
**
**Parameters:
** None
**
**Returns:
** None
**
**---------------------------------------------------------------------------
*/
extern void hdwinit(void);
bit rx_flag;
bit sd_flag;
unsigned char TEMP;
void UART6_Init( void )
{
ASIM6 = 1; /* ENABLE INTERNAL CLOCK OPERATION*/
SetIORBit(P4, 0x08); /* port setting in transmit/receive mode */
ClrIORBit(PM4, 0x08);
SetIORBit(PM4, 0x10);
SetIORBit(ASIM6, 0x04); /* data length 8 bits */
SetIORBit(ASIM6, 0x10); /* odd bits */
ClrIORBit(ASIM6, 0x02); /* stop length 1 bit */
SetIORBit(ASICL6, 0x02); /* LSB-first transfer */
CKSR6 = 0x1; /* baudrate selection 9600*/
BRGC6 = 0xd0;
ClrIORBit(IF1, 0x60);
ClrIORBit(MK1, 0x60); /* UART6 transmit/receive end interrupt enable */
SetIORBit(ASIM6, 0x80);
SetIORBit(ASIM6, 0x60); /* UART6 transmit/receive mode */
}
bit SENDCHAR(UCHAR TEMP)
{
sd_flag = 0;
TXB6 = TEMP;
while(!sd_flag);
return 1;
}
bit SENDSTRING(UCHAR *databuf, UCHAR txnum,UCHAR format)
{
UCHAR i = 0;
for(i=0;i<txnum;i++)
{
TEMP = *(databuf+i);
SENDCHAR(TEMP);
}
if(format)
{
TEMP ='\n';
SENDCHAR(TEMP);
}
return 1;
}
__interrupt void MD_INTST6( void )
{
sd_flag = 1;
}
__interrupt void MD_INTSR6( void )
{
rx_flag = 1;
}
void delay(int ms)
{
while(ms--);
}
void main( void )
{
hdwinit();
UART6_Init();
SENDSTRING("HELLO BOY",9,1);
while(1)
{
while(rx_flag)
{
rx_flag = 0;
SENDSTRING("RECEIVE DATA:",13,0);
SENDCHAR(RXB6);
SENDCHAR('\n');
}
}
}
串口通讯ourdev_394495.rar(文件大小:53K) (原文件名:USART.rar)
看看 呵呵 dongdaxing ,谢谢你热心支持本论坛。 ASIM6 = 1;
这一句什么意思,一个十进制的数1是直接赋给最高位了吗?如果是,那为什么后面还有一句SetIORBit(ASIM6, 0x80); ,作用不是重复的吗 ASIM6 = 1; 给这个寄存器赋值为1
SetIORBit(ASIM6, 0x80); 最高位置1 帮忙看一下,我这个串口为什么烧到板子中就没波形了
#pragma nop
#include "macrodriver.h"
#include "system.h"
extern void hdwinit(void);
void UART6_Init( void )
{
SetIORBit(P4, 0x08); /* port setting in transmit/receive mode */
ClrIORBit(PM4, 0x08);
SetIORBit(PM4, 0x10);
SetIORBit(ASIM6, 0x04); /* data length 8 bits */
ClrIORBit(ASIM6, 0x18); /* NO bits */
ClrIORBit(ASIM6, 0x02); /* stop length 1 bit */
SetIORBit(ASICL6, 0x02); /* LSB-first transfer */
CKSR6 = 0x01; /* baudrate selection 9615*/
BRGC6 = 0xd0;
ClrIORBit(IF1, 0x60);
ClrIORBit(MK1, 0x60); /* UART6 transmit/receive end interrupt enable */
SetIORBit(ASIM6, 0x80);
SetIORBit(ASIM6, 0x60); /* UART6 transmit/receive mode */
}
void UART_send(char data)
{
if(STIF6!=0)
{
STIF6=0;
data=(data>>7)|(data<<1);
}
TXB6=data;
}
void delay(int ms)
{
while(ms--);
}
void main( void )
{
hdwinit();
UART6_Init();
while(1)
{
UART_send(0x55);
}
}
系统时钟设置:
void Clock_Init( void )
{
ClrIORBit(PPCC, 0x03);
ClrIORBit(PCC, 0x02);
}
可选字节为0x9c
麻烦了 已经解决了,呵呵!!
页:
[1]