demo.c
来自「IAR-2148.rar 这是IAR上做的2148所有的例程」· C语言 代码 · 共 93 行
C
93 行
/******************************************************************************
Example program to show how to send characters out of UART0 by polling. Char-
acters are sent out at rate of 1 every 10milliseconds. The data to be trans-
mitted is stored in a static string that wraps to beginning when the last char-
acter in the buffer is sent.
This example does not use the PLL to mulitply the main clock frequency, so the
main bus is running at 12MHz and the peripheral clock at 3MHz.
Notice that in this example, the statement VICVectAddr = 0; which is necessary
to signal the completion of an interrupt service routine, has been moved to
the __irq function. If you have a lot of interrupt sources, this saves redund-
ancy in code.
The foreground task transmits the characters every time the 50msec timer
expires. Use hyperterm or other terminal emulator with no flow control.
9 Jun 05
Usage note: if you do not see characters on hyperterm, halt the program by
clicking on the red hand, then restart.
10 Jun 05
Enabling FIFO buffers with U1FCR = 1; per Anders Lundgren's advice.
******************************************************************************/
#include "demo.h"
void PWM5_Beep_Test(void);
void main(void)
{
char *ptr2Str = &textString[0];
/* This if-else statement detects if interrupt vectors located by the linker
command file are at memory location 0 or not. If so, MEMMAP is set to 1 to run
program out of flash
*/
#pragma segment = "INTVEC"
if (( void * )0x00000000UL == __segment_begin( "INTVEC" ))
{
MEMMAP = 1; // normal flash mode
}
else
{
MEMMAP = 2 ; // user ram mode - Map lowest 64 bytes of the address space to
//bottom of internal RAM, moving exception vectors into place
}
/*Configure the pins that are connected to RX and TX on UART1 */
PINSEL0 = (1<<ENABLE_UART1_RX) | (1<< ENABLE_UART1_TX); // PINSEL0 = 0x50000
/*Configure UART1 to 9600 buad, 8 bit, 1 stop, no parity */
U1FCR = 1; // Enable FIFOs whether used or not
SetBit(U1LCR,DIVISOR_LATCH_SET_bit); // U1LCR = 0X80-enable access to divisor
// latch bit, necessary for setting baud rate
U1LCR |= EIGHT_BIT_CHARS; // Eight bits U1LCR = 0X83
ClrBit(U1LCR,PARITY_ENABLE_bit); // No parity
ClrBit(U1LCR,STOP_BIT_SELECT_bit); // One stop bit
U1DLL = PCLKFREQ / (9600 * 16);
U1DLM = (PCLKFREQ / (9600 * 16)) >> 8;
ClrBit(U1LCR,DIVISOR_LATCH_SET_bit); // Disable access to divisor latch
/*This is the foreground loop, which looks at data coming from the background
loop. The user can insert own code to react to timer and button driven
events */
//Set PWM2
PINSEL0 = PINSEL0&~(3<<14);//clear
PINSEL0 = PINSEL0 | (0x2<<14);//set P0.7 to PWM2
PWM5_Beep_Test(); //PWM2 Test
while(TRUE) // Foreground Loop
{
if(*ptr2Str == '\0')
{
sendByte(0xD); // carriage return;
sendByte(0xA); // line feed
ptr2Str = &textString[0]; // wrap to start of string
}
sendByte(*ptr2Str++); // transmit next character
} // end foreground loop
} // end main()
void sendByte(char byte)
{
while (!(U1LSR &0x20)); //U1THR THRE bit set when U1THR contains valid data
U1THR = byte;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?