| |||||
Technical Support Support Resources
Product Information | C166: HOW TO GET 16-BIT ADDRESSES INTO THE PEC REGISTERS?Information in this article applies to:
SYMPTOMSHelp. I'm using C166 and I'm having trouble getting real 16-bit addresses into the PEC source and destination registers. How do I do that? CAUSEThe library function _sof_ must be used to get the real 16-bit address for segment 0 addresses. This function combines the segment (DPP register) and offset to get a real 16-bit address. RESOLUTIONThe following example program should help. It transmits a string out the serial port using PEC channel 0.
#include "reg167.h"
#include "intrins.h"
const char string1 [] = "0123456789\n"; // must be located in segment 0!
// This function initializes PEC Channel 0 to move the data from
// STRING1 to the serial transmit buffer.
void serial_PEC0_setup (void)
{
PECC0 = 0x0500 // Move Bytes, Inc Src Ptr
| ((sizeof (string1) / sizeof (string1 [0])) - 1);
SRCP0 = _sof_ (string1); // Source is STRING1
DSTP0 = 0x00FEB0; // Destination is the serial output
}
// The Serial TX interrupt just resets PEC 0 and transfers another
// copy of STRING 1.
void serial_TX_irq (void) interrupt S0TINT = 42
{
serial_PEC0_setup ();
}
void serial_baudrate (unsigned int baud)
{
S0BG = (20000000UL / (32UL * (unsigned long) baud));
}
// The setup routine for the serial port also initialized the PEC 0
// transfer and sets a TX interrupt request
void serial_setup (unsigned int baud)
{
serial_baudrate (baud);
DP3 |= 0x0400; // Set TXD for output
DP3 &= ~0x0800; // Set RXD for input
P3 |= 0x0400; // Set TXD high
S0CON = 0x8011;
S0TIC = 0x00F8; // Serial TX IRQ = Level 14, Priority 0 (PEC 0)
serial_PEC0_setup ();
IEN = 1; // Enable interrupts
}
void main (void)
{
serial_setup (19200);
while (1)
{
}
}
MORE INFORMATION
SEE ALSOFORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Monday, March 05, 2007 | ||||
| |||||