Wednesday, June 8, 2011

Library RS485 แบบ Half for LPC2368

/****************************************************************/
/* Compiler : Keil Realview MDK V4.13a */
/* Target MCU : Philips ARM7-LPC2368 */
/* : X-TAL : 12.00 MHz */
/* : PLL Setup = MSEL(12),NSEL(1) */
/* Create By : Eddy */
/* Last Update : 1/April/2011 */
/* Function : Example Use printf and scanf pass UART0*/
/*****************************************************************/

#include "stdio.h"

// Pin I/O LED Control Maskbit
#define DIR_RS485 0x00080000 // P1.19(0000 0000 0000 x000 0000 0000 0000 0000)
#define RXD_RS485() IOCLR1 = DIR_RS485 // RS485 Direction = 0 (Receive)
#define TXD_RS485() IOSET1 = DIR_RS485 // RS485 Direction = 1 (Transmit)

char uart3_buf[]; // "sprint" UART[0] Buffer



void init_serial3 (void)
{
// Config UART-3(RS422/485) Connect to P0[0]:P0[1]
PINSEL0 &= 0xFFFFFFF0; // Reset P0.0,P0.1 Pin Config
PINSEL0 |= 0x00000002; // Select P0.0 = TxD(UART3)
PINSEL0 |= 0x00000008; // Select P0.1 = RxD(UART3)
PCONP |= 0x02000000; // UART3 Power-ON
// Config P1.19 = Output Control Direction RS485
// P1.19 = "0" = Received RS485
// P1.19 = "1" = Transmit RS485
PINSEL3 &= 0xFFFF3FFF; // P1.19 = GPIO
IODIR1 = 0x00080000; // Pin Control Direction RS485 = Output


U3LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
//****************Baudrate UART = 115200,N,8,1***********************
U3DLL = 0x03; // DLM=DLest[15:8],DLL=DLest[7:0]
U3FDR = 0x67; // Fractional Divider--DivAddVal[3:0]/MulVal[7:4] = 1/2
U3LCR = 0x03; // DLAB = 0
}
/******************************/
/* Write Character To UART[3] */
/******************************/
void putchar3 (int ch)
{
TXD_RS485();
if (ch == '\n')
{
while (!(U3LSR & 0x20)); // Wait TXD Buffer Empty
U3THR = 0x0D; // Write CR
}

while (!(U3LSR & 0x20)); // Wait TXD Buffer Empty
U3THR = ch;
}
/******************************/
/* Get character From UART[3] */
/******************************/
int getchar3()
{
RXD_RS485();
while (!(U3LSR & 0x01)); // Wait RXD Receive Data Ready
return (U3RBR); // Get Receice Data & Return
}
/***************************/
/* Print String to UART[3] */
/***************************/
void print_uart3(void)
{
char *p; // Pointer Buffer
p = uart3_buf; // UART Buffer
do // Get char & Print Until null
{
putchar3(*p); // Write char to UART
p++; // Next char
}
while(*p != '\0'); // End of ASCII (null)
return;
}
/***********************/
/* Delay Time Function */
/* 1-4294967296 */
/***********************/
void delay(unsigned long int count1)
{
while(count1 > 0) {count1--;} // Loop Decrease Counter
}

Wednesday, June 1, 2011

Calibrating the ADE7753 for Watt, VAR, RMS, and VA measurements

images by free.in.th
Thanks: ฝากรูป

การปรับค่า ADE7753 สำหรับการวัด Watt, VAR, RMS และ VA
Download :
Mirror1: Calibrating_ADE7753.pdf
Mirror2: Calibrating_ADE7753.pdf
               
Reference : http://wenku.baidu.com/view/5e9db22c2af90242a895e590.html