Saturday, April 23, 2011
The CP-JR ARM7 LPC2368 Board Vs. SD/MMC card
ฝากรูป
กำลังอ่าน ลิ้งนี้อยู่ สัญญาว่าจะทำมันให้ได้ เพื่อทุกคน
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
}
Tuesday, April 19, 2011
Saturday, April 16, 2011
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.
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.. ด้วย
Subscribe to:
Posts (Atom)