|
/*
*******************************************************************************
** daxinganling@hotmail.com
** Filename : Receive And Send Uart6 in interrupt mode
** Abstract : This file implements main function.
** APIlib : NEC78K0SKX1+.lib V1.70 [7 Dec. 2006]
**
** 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)
看看 呵呵 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|