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

Sunday, May 29, 2011

LPC2368 GPIO-0 Interrupt

image by free.in.th
ฝากรูป

/******************************************************************************/
/****                               LPC2368 GPIO-0 Interrupt example by Musaho                            ****/
/******************************************************************************/



void Sensing_irq(void) __irq;

int main(void){

PINSEL1       = (3UL<<16);        //xxxx xxxx xxxx xx00 xxxx xxxx xxxx xxxx ,select to GPIO port P0.24
PINMODE1  = ~(3UL<<16);      // Resistor is pull up. 
PCLKSEL1   = ~(3UL<<2);        //PCLK_GPIO=CCLK/4
FIO0DIR       = ~(1UL<<24);        // Bit-24 is set to input.

IO0_INT_EN_F = (1UL<<24); //bit-24 are set up for the Falling edge interrupt.


VICVectAddr17     = (unsigned)Sensing_irq;
VICVectPriority17 =  0x00000000;   //IENT3
VICIntEnable     |= (1UL<<17); // select IENT3 interrupt

while(1);


}


void Sensing_irq(void) __irq //Sensing interrupt P0.24
{

/****************************************************************/
/*                                       Your Interrupt program is here                                       */
/****************************************************************/


IO0_INT_CLR = (1UL<<24); //clear the GPIO-0, P0.24 interrupt flag
VICVectAddr = 0x00000000; // *Dummy Write to signal end of Interrupt.
return;
}

Saturday, April 23, 2011

The CP-JR ARM7 LPC2368 Board Vs. SD/MMC card

image by free.in.th
ฝากรูป


กำลังอ่าน ลิ้งนี้อยู่ สัญญาว่าจะทำมันให้ได้ เพื่อทุกคน
FatFs Generic FAT File System Module และ Interfacing ARM controllers with Memory-Cards

Friday, April 22, 2011

RTC + interrupt 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 : 22/April/2011 */
/* Function : Example Use RCT */
/****************************************************/
// Read/Write Internal RTC of LPC2368
// Display Result on UART0(115200,N,8,1)

#include "LPC23xx.H" // LPC2368 MPU Register
#include // For Used Function printf

#define MASKSEC 0x0000003F // Second 00..59 000000000:00000000:00000000:00xxxxxx
#define MASKMIN 0x00003F00 // Minute 00..59 000000000:00000000:00xxxxxx:00000000
#define MASKHR 0x001F0000 // Hour 00..23 000000000:000xxxxx:00000000:00000000
#define MASKWEEK 0x7000000 // Week 00..6 000000xxx:00000000:00000000:00000000

// Pin I/O LED Control Maskbit
#define LED1 0x02000000 // P3.25(0000 00x0 0000 0000 0000 0000 0000 0000)
#define LED2 0x04000000 // P3.26(0000 0x00 0000 0000 0000 0000 0000 0000)

#define LED1_ON() FIO3CLR = LED1 // LED1 Pin = 0 (ON LED)
#define LED1_OFF() FIO3SET = LED1 // LED1 Pin = 1 (OFF LED)
#define LED2_ON() FIO3CLR = LED2 // LED2 Pin = 0 (ON LED)
#define LED2_OFF() FIO3SET = LED2 // LED2 Pin = 1 (OFF LED)

char alarm=0,sec_change=0;


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

/* pototype section */
void init_serial0 (void); // Initil UART-0
void putchar0(char ch); // Put Char To UART-0
char getchar0(void); // Get Char From UART-0
void print_uart0(void); // Print String to UART0
void delay(unsigned long int); // Delay Time Function


void RTC_isr(void) __irq
{
unsigned char Week,Hour,Minute,Second,Last_Second; // RTC Buffer Data
unsigned led;

if (RTC_ILR & 0x00000001)
{
led = FIO3PIN;
FIO3CLR = led&LED1;
FIO3SET = ~led&LED1;
do // Repeat Get Second until Second Change
{
Week = (RTC_CTIME0 & MASKWEEK)>>24; // Read Week
Hour = (RTC_CTIME0 & MASKHR)>>16; // Read Hour
Minute = (RTC_CTIME0 & MASKMIN)>>8; // Read Minute
Second = RTC_CTIME0 & MASKSEC; // Read Second
}
while(Last_Second == Second); // Repeat if Second Not Change
Last_Second = Second; // Update Current Second
//************************************//
// Display Clock = Hour:Minute:Second //
//************************************//
sprintf(uart0_buf,"\r\nReal Time Clock = %2d : %2d : %2d : %2d",Week,Hour,Minute,Second); // Print Message String
print_uart0();
if (Second != 0x00000003)
{
sprintf(uart0_buf,"\nIRQ");
print_uart0();
}
//sec_change=1;
RTC_ILR = 0x00000001;
}
if (RTC_ILR & 0x00000002)
{
//alarm=1;
sprintf(uart0_buf,"\nalarm");
print_uart0();
FIO3SET = LED2;
RTC_ILR = 0x00000002;
}
VICVectAddr = 0x00000000;
}

int main(void)
{
// unsigned char Week,Hour,Minute,Second,Last_Second; // RTC Buffer Data
init_serial0(); // Initilial UART0 = 9600,N,8,1
/*Config Pin GPIO3[26:25]*/
PINSEL7 &= 0xFFC3FFFF; // P3[26:25] = GPIO Function(xxxx xxxx xx00 00xx xxxx xxxx xxxx xxxx)
PINMODE7 &= 0xFFC3FFFF; // Enable Puul-Up on P3[26:25]
FIO3DIR |= LED1; // Set GPIO-3[26:25] = Output(xxxx x11x xxxx xxxx xxxx xxxx xxxx xxxx)
FIO3DIR |= LED2;

RTC_DOW = 3; // Setup Day of Week
RTC_HOUR = 22; // Setup Hour
RTC_MIN = 19; // Setup Minute
RTC_SEC = 5; // Setup Second
RTC_CCR = 0; // Reset All Bit Control
RTC_CCR |= 0x00000010; // CLKSRC = 1 = Used EXT 32.768 KHz
RTC_CCR |= 0x00000002; // Reset Clock
RTC_CCR &= 0xFFFFFFFD; // Release Reset
RTC_CIIR = 0x000000001; // Enable seconds counter interrupt
RTC_ALSEC = 0x00000003; // Set alarm register for 3 seconds
RTC_AMR = 0x000000FE; // Enable seconds Alarm
RTC_CCR |= 0x00000001; // Start RTC Clock


VICVectAddr13 = (unsigned)RTC_isr; //Set the timer ISR vector address
VICVectPriority13 = 0x0000002D; //Set channel
VICIntEnable = 0x00002000; //Enable the interrupt



}

/********************************/
/* Initial UART0 = 115200,N,8,1 */
/********************************/
void init_serial0 (void)
{
PINSEL0 &= 0xFFFFFF0F; // Reset P0.2,P0.3 Pin Config
PINSEL0 |= 0x00000010; // Select P0.2 = TxD(UART0)
PINSEL0 |= 0x00000040; // Select P0.3 = RxD(UART0)
U0LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
U0DLL = 3; // Baud 115200BPS for 12MHz PCLK Clock
U0FDR = 0x67; // Fractional Divider
U0LCR = 0x03; // DLAB = 0
}

/******************************/
/* Write Character To UART[0] */
/******************************/
void putchar0 (char ch)
{
if (ch == '\n')
{
while (!(U0LSR & 0x20)); // Wait TXD Buffer Empty
U0THR = 0x0D; // Write CR
}

while (!(U0LSR & 0x20)); // Wait TXD Buffer Empty
U0THR = ch;
}

/******************************/
/* Get character From UART[0] */
/******************************/
char getchar0()
{
while (!(U0LSR & 0x01)); // Wait RXD Receive Data Ready
return (U0RBR); // Get Receice Data & Return
}

/***************************/
/* Print String to UART[0] */
/***************************/
void print_uart0(void)
{
char *p; // Pointer Buffer
p = uart0_buf; // UART Buffer
do // Get char & Print Until null
{
putchar0(*p); // Write char to UART
p++; // Next char
}
while(*p != '\0'); // End of ASCII (null)
return;
}

void delay(unsigned long int count1)
{
while(count1 > 0) {count1--;} // Loop Decrease Counter
}



Thursday, April 7, 2011

Timer0 Interrupt in 1s on ARM7-LPC2368 Port P1.24 and P1.25

Testing of Timer0 and Interrupt in 1 second on ARM7-LPC2368. By using CP-JR ARM7 LPC2368 develop board from ETT. Co., LTD. The CCLK has a speed of 48MHz, PCLK is set as CCLK/4=12MHz. Two signals are measured from P1.24 and P1.25 as shown in the figure.

Convert Video file. โปรแกรมแปลงไฟล์ Video ใช้ได้ทุกนามสกุล

เป็นโปรแกรมฟรีแวร์นะครับ ลองๆ กันดู
FFsetup240.zip.001
FFsetup240.zip.002
FFsetup240.zip.003

Friday, April 1, 2011

printf and scanf in Keil with RealView Compiler



สำหรับการใช้ high-level formatted IO library function ใน Keil เราจำเป็นต้องเตรียม low-level driver ให้เหมาะสมกับ อุปกรณ์ IO ที่เราจะใช้ โดยสำหรับ low-level functions ดังกล่าว Real View library ได้เตรียมไว้แล้วใน file "retarget.c" ซึ่งถูกเก็บในkeil\arm\startup โดย printf และ scanf ก็ถูกเก็บไว้ใน "Retarget.c" ดังนั่น เราต้องนำ "retarget.c" มา add ใน project>>Manage>>Components,Environment,Book.. ด้วย

Thursday, March 31, 2011

LPC2368 ทดสอบ Timer0 Interrupt

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


/****************************************************/
/* Examples Program For "CP-JR ARM7 LPC2368" */
/* Target MCU : Philips ARM7-LPC2368 */
/* : X-TAL : 12.00 MHz */
/* : PLL Setup = MSEL(12),NSEL(1) */
/* Keil Editor : uVision3 V4.13a */
/* Compiler : Keil Realview MDK V4.13 */
/* Create By : Musa */
/* Last Update : 30/March/2011 */
/* Function : TimerInterrupt.c/TimerInterrupt.hex */
/****************************************************/
#include "LPC23xx.H"

Wednesday, March 30, 2011

LPC2368_I2C_Interface



/****************************************************/
/* Examples Program For "CP-JR ARM7 LPC2368" */
/* Target MCU : Philips ARM7-LPC2368 */
/* : X-TAL : 12.00 MHz */
/* : PLL Setup = MSEL(12),NSEL(1) */
/* : CCLK = 4, USB = 2, PLCK0,1 = cclk/4*/
/* : SYSTEMcclk = 72MHz, USB = 36MHz */
/* : PLCK = 18MHz */
/* Keil Editor : uVision4 V4.14 */
/* Compiler : Keil Realview MDK V3.20 */
/* Create By : MAN */
/* Last Update : 30/March/2011 */
/* Function : Example Use I2C0 Interface 24LCxx */
/* : EEPROM in Master Mode */
/****************************************************/
/***** Header File *****/
#include < LPC23xx.H > // Header File LPC2368
#include < stdio.h > // Use sprintf

Sunday, March 27, 2011

LPC2368_SPI_Interface


/**********************************************************/
/* Examples Program For "CP-JR ARM7 LPC2368" */
/* Target MCU : Philips ARM7-LPC2368 */
/* : X-TAL : 12.00 MHz */
/* : PLL Setup = MSEL(12),NSEL(1) */
/* : CCLK = 4, USB = 6, PLCK0,1 = cclk/4 */
/* : SYSTEMcclk = 72MHz, USB = 48MHz */
/* : PLCK = 18MHz */
/* Keil Editor : uVision4 V4.14 */
/* Compiler : Keil Realview MDK V3.20 */
/* Create By : MAN */
/* Last Update : 9/March/2011 */
/* Function : Example Use SPI Interface MCP3202 */
/* : and MCP4821 */
/**********************************************************/

#include < LPC23xx.H > // LPC2368 MCU Register
#include < stdio.h > // For Used Function printf

Saturday, March 26, 2011

LPC2368 การดักจับสัญญาณ Interrupt และการกระโดดไปยัง routine ของ ARM7 Realview-Compiler

void sio_irq (void) __irq
{
  /* ใส่โค้ดที่ต้องการให้ทำงานเมื่อเกิด Interrupt */


T0IR = 0x00000001; //clear the interrupt flag
         // *The interrupt flag must be cleared to reset- 
                                                       //interruption. 

VICVectAddr=0;                                          //Acknowledge interrupt
}


Example ARM programing with Realview Compiler

http://www.keil.com/download/list/arm.htm