This document contains procedures for interfacing a buzzer, relay, and LED with an ARM 7 microcontroller using C programming. It includes the theory of operation for relays and LEDs. The procedures describe how to create a new project in IAR workbench, write C code to control the devices, and download the program to the microcontroller. C code examples are provided to turn the buzzer, relay, and LEDs on and off in sequences with delays. The aim is to design and verify the interfacing of these devices using ARM 7 technology.
This document contains procedures for interfacing a buzzer, relay, and LED with an ARM 7 microcontroller using C programming. It includes the theory of operation for relays and LEDs. The procedures describe how to create a new project in IAR workbench, write C code to control the devices, and download the program to the microcontroller. C code examples are provided to turn the buzzer, relay, and LEDs on and off in sequences with delays. The aim is to design and verify the interfacing of these devices using ARM 7 technology.
CREATED BY T.BHARATHRAMAN ASSISTANT PROFESSOR DEPARTMENT OF ECE
MRK IT
INTERFACING USING C PROGRAM AIM: To design a) Buzzer b) Relay and Interfacing of relay with buzzer using ARM 7 technology. APPARATUS REQUIRED: SOFTWARE: IAR system workbench HARDWARE: RS232 CABLE, ARM 7, Adapter (0 5V) OPERATING SYSTEM: Windows XP THEORY: One end of the electromagnet wire is connected directly to one end of the electrical circuits. The other end of the wire connects to a metal contact which is adjacent to a moving arm. The contact arm is a thin piece of light conductive metal, with a thin iron bar soldered to the electrical circuit. When turned off, the free end of the ARM resets against the contact point. This forms a connection between that the end of the circuit. In this circuit, a switch is controlling power to the electromagnet. When it is switched ON, the electromagnet attracts the armature. The armature is acting as a switch in the second circuit. When the electromagnet is energized, the armature completes the second circuit. When the electromagnet is not energized the spring pulls the armature energy and the circuit is not complete. When your propose relay, you generally have control over several variables. The voltage and current that is needed to activate the armature. The maximum voltage and current that can run through the armature and the armature contacts the number of armature( generally one to two). The number of contacts for the armature whether the contact is normally open or normally closed. PROCEDURE: FOR CREATING NEW PROJ ECT: Open IAR embedded workbench To create a new project, choose project and select create new project. MRK IT
Give a file name for the project. Choose FILE menu and select NEW file. Edit the application code in C language. To save the C file choose file and then select Save As and save the file with the extension of .c [filename.c]. In the workspace window, select the file name and then right click on the file, choose Add and Add filename.c. Then choose options on the same workspace window. Choose Device as NXP NXPLPC2148. Choose Linker in the category and select the override default. In that menu, choose <filename.hex> Select others output format as Intel extended. Choose config menu to select override default. In that box, choose the path IAR systems embedded workbench 4.0 kickstart ARM examples NXP LPC214X IAR-LPC-214X ADC configuration flash.xcl. Right click on the workspace for rebuilding the program. FOR DOWNLOADING THE PROGRAM: In step 1 choose COM Port COM 1 Baud rate 9600 Device LPC 2148 Interface None Oscillator frequency 12MHz In step 2 select Erase blocks used by Hex file; In step 3 browse the hex file. In step 4 select Verify after programming. MRK IT
Then click the Start button.
PROGRAM FOR BUZZER FUNCTIONING: #include<iolpc2148.h> void LPC2148PLLInit(void); unsigned int i; void delay_ms() { int i; for(i=0;i<0xffff;i++); } void main() { PINSEL0 =0x00000000; // PINSEL(0,1,2) =0 configures pins as GPIO PINSEL1 =0x00000000; // (probably not necessary: PINSELs default to zero) PINSEL2 =0x00000000; // except P0.24, which doesn't exist on LPC2148 IO0DIR =0xFFFF0000; // IO0DIR will be configured as Input pin. IO1DIR =0xFFff0000; // only P1.16 to p1.23 pin will be configured as Output Pin. //LPC2148PLLInit(); while(1) { IO0SET=0x02000000 ; delay_ms();
IO0CLR=0x02000000 ; MRK IT
delay_ms(); } } void LPC2148PLLInit(void) { int loop_ctr; /* Configure PLL0, which determines the CPU clock */ PLLCFG =0x00000024; /* Use PLL values of M =4 and P =2 */ PLLCON_bit.PLLE =1; /* Set the PLL Enable bit */ PLLFEED =0xAA; /* Write to the PLL Feed register */ PLLFEED =0x55; loop_ctr =10000; /* Wait for the PLL to lock into the new frequency */ while (((PLLSTAT_bit.PLOCK) ==0) && (loop_ctr >0)) { loop_ctr--; } PLLCON_bit.PLLC =1; /* Connect the PLL */ PLLFEED =0xAA; /* Write to the PLL Feed register */ PLLFEED =0x55; // VPBDIV =0x00000001; /* Set the VPB frequency to one-half of the CPU clock */ }
PROGRAM FOR RELAY FUNCTIONING: #include <iolpc2148.h> static void delay(void ) { MRK IT
volatile int i,j; for (i=0;i<0x7F;i++) for (j=0;j<300;j++); } void main() { PINSEL1 =0x00000000; IO0DIR =0x00F00000; //0000 0000 0000 0000 while(1) { IO0SET =0X00F00000; delay(); IO0CLR =0X00F00000; delay(); } } PROGRAM FOR INTERFACING OF RELAY WITH BUZZER: #include <iolpc2148.h> static void delay(void ) { volatile int i,j; for (i=0;i<0x7F;i++) for (j=0;j<300;j++); } void main() MRK IT
RESULT: Thus the interfacing of Buzzer with Relay is designed using ARM 7 technology and its output was verified.
MRK IT
LED INTERFACE AIM: To display the status of LED with delay using ARM 7 technology. APPARATUS REQUIRED: SOFTWARE: IAR system workbench HARDWARE: RS232 CABLE, ARM 7, Adapter (0 5V) OPERATING SYSTEM: Windows XP THEORY: This experiment is to glow the light emitting diode (LED). LED is a special diode that emits light upon application of a potential difference greater than its forward bias voltage across its terminals. A LED can be forward biased or reverse biased. The ARM LPC controller pins numbered H16, H8, H48, H44, H40 and H36 are used to drive the buffer 744C 2 44. PROCEDURE: FOR CREATING NEW PROJ ECT: Open IAR embedded workbench To create a new project, choose project and select create new project. Give a file name for the project. Choose FILE menu and select NEW file. Edit the application code in C language. To save the C file choose file and then select Save As and save the file with the extension of .c [filename.c]. In the workspace window, select the file name and then right click on the file, choose Add and Add filename.c. Then choose options on the same workspace window. Choose Device as NXP NXPLPC2148. MRK IT
Choose Linker in the category and select the override default. In that menu, choose <filename.hex> Select others output format as Intel extended. Choose config menu to select override default. In that box, choose the path IAR systems embedded workbench 4.0 kickstart ARM examples NXP LPC214X IAR-LPC-214X ADC configuration flash.xcl. Right click on the workspace for rebuilding the program. FOR DOWNLOADING THE PROGRAM: In step 1 choose COM Port COM 1 Baud rate 9600 Device LPC 2148 Interface None Oscillator frequency 12MHz In step 2 select Erase blocks used by Hex file; In step 3 browse the hex file. In step 4 select Verify after programming. Then click the Start button. PROGRAM FOR LED FUNCTIONING: #include<iolpc2148.h> void LPC2148PLLInit(void); unsigned int i; void delay_ms() { int i,j; for(i=0;i<0xff;i++) MRK IT
for(j=0;j<0xff;j++); } void main() { PINSEL0 =0x00000000; // PINSEL(0,1,2) =0 configures pins as GPIO PINSEL1 =0x00000000; // (probably not necessary: PINSELs default to zero) PINSEL2 =0x00000000; // except P0.24, which doesn't exist on LPC2148 IO0DIR =0xFFFFFFFF; IO1DIR =0x00ff0000; // only P1.16 to p1.23 pin will be configured as Output Pin. IO0CLR =0xFFFF0000; while(1) { for(i=0;i<5;i++) { IO1SET=0x00ff0000; delay_ms(); IO1CLR=0x00ff0000; delay_ms(); }
} delay_ms(); } } void LPC2148PLLInit(void) { int loop_ctr; /* Configure PLL0, which determines the CPU clock */ PLLCFG =0x00000024; /* Use PLL values of M =4 and P =2 */ PLLCON_bit.PLLE =1; /* Set the PLL Enable bit */ PLLFEED =0xAA; /* Write to the PLL Feed register */ PLLFEED =0x55; loop_ctr =10000; /* Wait for the PLL to lock into the new frequency */ while (((PLLSTAT_bit.PLOCK) ==0) && (loop_ctr >0)) { loop_ctr--; } PLLCON_bit.PLLC =1; /* Connect the PLL */ PLLFEED =0xAA; /* Write to the PLL Feed register */ PLLFEED =0x55; // VPBDIV =0x00000001; /* Set the VPB frequency to one-half of the CPU clock */ }
RESULT: Thus the program for LED functioning is developed and implemented using ARM 7 technology.
MRK IT
SEVEN SEGMENT DISPLAY AIM: To develop a program for the seven segment display and implementing using the ARM 7 technology. APPARATUS REQUIRED: SOFTWARE: IAR system workbench HARDWARE: RS232 CABLE, ARM 7, Adapter (0 5V) OPERATING SYSTEM: Windows XP THEORY: A seven segment display is a form of an electronic display device displaying decimal numerical. They are commonly used in digital clocks, electronic meters etc. There are two types of displays available, common anode and common cathode. The LED is an seven segment display which is not isolated from each other. In common cathode, cathodes are connected together and the anodes are connected individually. In this, we need to give 1 as an input for all LEDs to glow. In common anode, all anodes are connected together while the cathodes are connected individually. In this, we need to give 0 as input for all LEDs to be glown. PROCEDURE: FOR CREATING NEW PROJ ECT: Open IAR embedded workbench To create a new project, choose project and select create new project. Give a file name for the project. Choose FILE menu and select NEW file. Edit the application code in C language. To save the C file choose file and then select Save As and save the file with the extension of .c [filename.c]. MRK IT
In the workspace window, select the file name and then right click on the file, choose Add and Add filename.c. Then choose options on the same workspace window. Choose Device as NXP NXPLPC2148. Choose Linker in the category and select the override default. In that menu, choose <filename.hex> Select others output format as Intel extended. Choose config menu to select override default. In that box, choose the path IAR systems embedded workbench 4.0 kickstart ARM examples NXP LPC214X IAR-LPC-214X ADC configuration flash.xcl. Right click on the workspace for rebuilding the program. FOR DOWNLOADING THE PROGRAM: In step 1 choose COM Port COM 1 Baud rate 9600 Device LPC 2148 Interface None Oscillator frequency 12MHz In step 2 select Erase blocks used by Hex file; In step 3 browse the hex file. In step 4 select Verify after programming. Then click the Start button. PROGRAM FOR SEVEN SEGMENT DISPLAY: #include<iolpc2148.h> #include<stdio.h> #define DESIRED_BAUDRATE 19200 MRK IT
#define CRYSTAL_FREQUENCY_IN_HZ 12000000 #define PCLK CRYSTAL_FREQUENCY_IN_HZ // since VPBDIV=0x01 #define DIVISOR (PCLK/(16*DESIRED_BAUDRATE)) int i,temp,Temp1,addr; int i2c0,i2c1,i2c2,l; unsigned char i2c_data[] ={0x00,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67}; static void delay(void ) { volatile int i,j; for (i=0;i<5;i++) for (j=0;j<50;j++); } static void delay1(void ) { volatile int i,j; for (i=0;i<100;i++) for (j=0;j<500;j++); } void i2c_write(char a,char add) { //START CONDITION I2C0CONSET=0x60; //0x60 change //start I2C data transmission when set STA flag. delay(); delay(); temp=I2C0STAT; while(temp!=0x08) MRK IT
RESULT: Thus the seven segment display was designed using ARM 7 technology.
MRK IT
DIP SWITCH AND LEDs AIM: To display the status of DIP switch on LEDs. APPARATUS REQUIRED: SOFTWARE: IAR system workbench HARDWARE: RS232 CABLE, ARM 7, Adapter (0 5V) OPERATING SYSTEM: Windows XP THEORY: A DIP switch is a set of manual electronics switch that are packed in a group of standard dual-in-line pin (DIP). This type of switch is designed to be used on a printed circuit board along with other electronic components and is commonly used to customize the behavior of an DIP switch as an alternative to jumper blocks. Their main advantages are they are quicker to change and these are no parts to lose. PROCEDURE: FOR CREATING NEW PROJ ECT: Open IAR embedded workbench To create a new project, choose project and select create new project. Give a file name for the project. Choose FILE menu and select NEW file. Edit the application code in C language. To save the C file choose file and then select Save As and save the file with the extension of .c [filename.c]. In the workspace window, select the file name and then right click on the file, choose Add and Add filename.c. Then choose options on the same workspace window. Choose Device as NXP NXPLPC2148. MRK IT
Choose Linker in the category and select the override default. In that menu, choose <filename.hex> Select others output format as Intel extended. Choose config menu to select override default. In that box, choose the path IAR systems embedded workbench 4.0 kickstart ARM examples NXP LPC214X IAR-LPC-214X ADC configuration flash.xcl. Right click on the workspace for rebuilding the program. FOR DOWNLOADING THE PROGRAM: In step 1 choose COM Port COM 1 Baud rate 9600 Device LPC 2148 Interface None Oscillator frequency 12MHz In step 2 select Erase blocks used by Hex file; In step 3 browse the hex file. In step 4 select Verify after programming. Then click the Start button. PROGRAM FOR SWITCH FUNCTIONING: #include <iolpc2148.h> #include <stdio.h> #define BAUD 19200 void ARM_INIT() { // P1.16 to P1.23 used for LED.and P1.24 to P1.31 used for DIP Switch. //GPIO Initialisation MRK IT
PINSEL0 =0x00000000; //Pin selection for GPIO PINSEL1 =0x00000000; //Pin selection for GPIO PINSEL2 =0x00000000; //Pin selection for GPIO IO1DIR =0X00FF0000; // P1.24 to P1.31 -->input and P1.16 to P1.23 -->output. IO0DIR =0xFFFFFFFF; } static void delay(void ) //delay routine { volatile int i,j; for (i=0;i<0x3F;i++) for (j=0;j<500;j++); } void main() { ARM_INIT(); // Initialize PORT pin IO0CLR =0xFFFF0000; while(1) { IO1CLR =0X00FF0000; //Clear Led Out. IO1SET =(IO1PIN & 0xff000000) >>0x08 ; //Read Switch status and switch //value send to LED PORT line delay(); } }
MRK IT
RESULT: Thus the status of the DIP switch was displayed on the LEDs using ARM 7 technology and its output was verified.
MRK IT
KEYPAD OPERATION USING LINUX AIM: To write a program for keypad operation using ARM 7 technology. APPARATUS REQUIRED: SOFTWARE: GTK term. HARDWARE: RS232 CABLE, ARM 7, Adapter (0 5V) OPERATING SYSTEM: Linux. THEORY: Switches are devices that have two positions ON and OFF, which have a toggle to establish or break a connection. The ViARM 2378 OEM board has 5 toggle switches. PROCEDURE: Right click on the desktop window in Linux Select the open terminal and choose the communication window. Type cd / command as the path changes as [ root @ Local host /]. Type cd VCP_15_Linux and the commands changes as [ root @ Local host VCP_15_Linux] # To open program, type cd <program name>, for eg. To open keypad program type cd keypad. To compile the program, use the command make all. Switch ON the kit and set the key in programming mode. To download the program to ARM 7, type the command .lpc21isp hex main.hex /dev/ttyS0 19200 12000 Where ttyS0 serial port 19200 Baud rate 12000 clock frequency. MRK IT
Keep the switch in the kit at execution mode for executing the program. Open the GTK terminal for displaying the output. CIRCUIT DIAGRAM:
PROGRAM FOR KEYPAD OPERATION: #include "LPC23xx.h" void delay(void) { for(int i=0;i<0x7f;i++) for(int j=0;j<0xff;j++); } void send_serial_data(int ch) { while ((U0LSR & 0x20)!=0x20); U0THR =ch; } void key_routine(void) { unsigned int key; FIO2DIR=0x000000F0; FIO4DIR=0X0000000f; while(1) {
MRK IT
FIO4SET=0X0000000E; switch (FIO4PIN&0XF) { case 0x6: send_serial_data('2'); break; case 0xa: send_serial_data('1'); break; case 0xc: send_serial_data('5'); break; } FIO4CLR=0X0000000E; delay(); FIO4SET=0X0000000D;
switch(FIO4PIN&0xf) { case 0xc: send_serial_data('3'); break; }
RESULT: Thus the program for keypad operation is performed using ASM 7 technology.
MRK IT
LED OPERATION USING LINUX AIM: To write a program for LED functioning using ARM 7 technology. APPARATUS REQUIRED: SOFTWARE: GTK term. HARDWARE: RS232 CABLE, ARM 7, Adapter (0 5V) OPERATING SYSTEM: Linux. THEORY: Light Emitting Diodes are most commonly used components for displaying pins digital state. ViARM 2378 has 8 LEDs that are connected to the port line. PROCEDURE: Right click on the desktop window in Linux Select the open terminal and choose the communication window. Type cd / command as the path changes as [ root @ Local host /]. Type cd VCP_15_Linux and the commands changes as [ root @ Local host VCP_15_Linux] # To open program, type cd <program name>, for eg. To open LED program type cd led. To compile the program, use the command make all. Switch ON the kit and set the key in programming mode. To download the program to ARM 7, type the command .lpc21isp hex main.hex /dev/ttyS0 19200 12000 Where ttyS0 serial port 19200 Baud rate 12000 clock frequency. Keep the switch in the kit at execution mode for executing the program. MRK IT
CIRCUIT DIAGRAM:
PROGRAM FOR LED OPERATION: #include "LPC23xx.h"
/***************************************************************************** ***************************** Routine to set processor and pheripheral clock ****************************************************************************** *****************************/ void TargetResetInit(void) { // 72 Mhz Frequency if ((PLLSTAT & 0x02000000) >0) { /* If the PLL is already running */ PLLCON &=~0x02; /* Disconnect the PLL */ PLLFEED = 0xAA; /* PLL register update sequence, 0xAA, 0x55 */ PLLFEED = 0x55; } PLLCON &=~0x01; /* Disable the PLL */ PLLFEED = 0xAA; /* PLL register update sequence, 0xAA, 0x55 */ PLLFEED = 0x55; SCS &=~0x10; /* OSCRANGE =0, Main OSC is between 1 and 20 Mhz */ MRK IT
SCS |= 0x20; /* OSCEN =1, Enable the main oscillator */ while ((SCS & 0x40) ==0); CLKSRCSEL =0x01; /* Select main OSC, 12MHz, as the PLL clock source */ PLLCFG =(24 <<0) | (1 <<16); /* Configure the PLL multiplier and divider */ PLLFEED =0xAA; /* PLL register update sequence, 0xAA, 0x55 */ PLLFEED =0x55; PLLCON |=0x01; /* Enable the PLL */ PLLFEED =0xAA; /* PLL register update sequence, 0xAA, 0x55 */ PLLFEED =0x55; CCLKCFG =3; /* Configure the ARM Core Processor clock divider */ USBCLKCFG =5; /* Configure the USB clock divider */ while ((PLLSTAT & 0x04000000) ==0); PCLKSEL0 =0xAAAAAAAA; /* Set peripheral clocks to be half of main clock */ PCLKSEL1 =0x22AAA8AA; PLLCON |=0x02; /* Connect the PLL. The PLL is now the active clock source */ PLLFEED =0xAA; /* PLL register update sequence, 0xAA, 0x55 */ PLLFEED =0x55; while ((PLLSTAT & 0x02000000) ==0); PCLKSEL0 =0x55555555; /* PCLK is the same as CCLK */ PCLKSEL1 =0x55555555; } // delay routine static void delay(void) { unsigned int i,j; for(i=0;i<0xff;i++) for(j=0;j<0x3ff;j++); } /************************* main routine ************************************************************/ int main () { unsigned char arr[5]={0x10,0x20,0x40,0x80,0xf0,0x00}; FIO2DIR=0xF0; init_timer(((72000000/100)-1)); while(1) { for(int i=0;i<=5;i++) { FIO2PIN=arr[i]; //9,6,5,a delay(); MRK IT
} } return 0; }
RESULT: Thus the program for LED operation is performed using ARM 7 technology.
MRK IT
ADC PROGRAMMING IN ZIGBEE AIM: To write a program for performing ADC operation using Zigbee modules. APPARATUS REQUIRED: SOFTWARE: Zigbee modules (2), Debugger module (1), RS232 cable (1), ZRF connector (1). HARDWARE: Smart RF Flash programmer, WinXTalk. OPERATING SYSTEM: Windows XP. THEORY: Zigbee is one of the advanced wireless technology and CC2430 is the first Single Chip IEEE 802.15.4 and Zigbee System On Chip (SOC) RF transceiver with integrated microcontroller. In this exercise, we establish communication between 2RF modules. These modules work in the ISM band of 2.4GHz and have a SPI interface through which they are controlled and configured. Being a transceiver, they establish full duplex communication. PROCEDURE: Open Smart RF programmer and connect the RF modules to the debugger using RF connector. The details of the chip is read and displayed in the window as soon as the connection is established. Select Retain IEEE address when reprogramming the chip. Click on the Read IEEE button to read the IEEE address of the module. PROGRAM FOR COORDINATOR: #include "OSAL.h" #include "ZGlobals.h" #include "AF.h" #include "aps_groups.h" #include "ZDApp.h"
uint8 s; uint8 buffer1=0; // This list should be filled with Application specific Cluster IDs. const cId_t Example_ClusterList[EXAMPLE_MAX_CLUSTERS] = { EXAMPLE_PERIODIC_CLUSTERID, EXAMPLE_FLASH_CLUSTERID, EXAMPLE_PERIODIC_CLUSTERID1, EXAMPLE_PERIODIC_CLUSTERID2, EXAMPLE_PERIODIC_CLUSTERID3, EXAMPLE_PERIODIC_CLUSTERID4, EXAMPLE_PERIODIC_CLUSTERID5, EXAMPLE_PERIODIC_CLUSTERID6, EXAMPLE_PERIODIC_CLUSTERID7 };
// This is the Endpoint/Interface description. It is defined here, but // filled-in in Example_Init(). Another way to go would be to fill // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t Example_epDesc; uint8 *data; byte *wdata; uint8 Example_TaskID; // Task ID for internal task/event processing MRK IT
// This variable will be received when // Example_Init() is called. devStates_t Example_NwkState;
uint8 Example_TransID; // This is the unique message ID (counter)
* @fn Example_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none void Example_Init( uint8 task_id ) { Example_TaskID =task_id; Example_NwkState =DEV_INIT; Example_TransID =0; MRK IT
Example_Seqnb =Example_Seqnb1 =0x00;
// Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main().
#if defined ( SOFT_START ) // The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START // SOFT_START is a compile option that allows the device to start // as a coordinator if one isn't found. // We are looking at a jumper (defined in ExampleHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJ umper() ) zgDeviceLogicalType =ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType =ZG_DEVICETYPE_ROUTER; #endif // SOFT_START
#if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif
// Setup for the periodic message's destination address // Broadcast to everyone Example_Periodic_DstAddr.addrMode =(afAddrMode_t)AddrBroadcast; Example_Periodic_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Periodic_DstAddr.addr.shortAddr =0xFFFF;
// Setup for the flash command's destination address - Group 1 Example_Flash_DstAddr.addrMode =(afAddrMode_t)afAddrGroup; Example_Flash_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Flash_DstAddr.addr.shortAddr =EXAMPLE_FLASH_GROUP;
// Fill out the endpoint description. Example_epDesc.endPoint =EXAMPLE_ENDPOINT; Example_epDesc.task_id =&Example_TaskID; Example_epDesc.simpleDesc =(SimpleDescriptionFormat_t *)&Example_SimpleDesc; Example_epDesc.latencyReq =noLatencyReqs;
// Register the endpoint description with the AF afRegister( &Example_epDesc );
// Register for all key events - This app will handle all key events RegisterForKeys( Example_TaskID ); MRK IT
// By default, all devices start out in Group 1 Example_Group.ID =0x0001; osal_memcpy( Example_Group.name, "Group 1", 7 ); aps_AddGroup( EXAMPLE_ENDPOINT, &Example_Group );
if ( events & SYS_EVENT_MSG ) { MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a key is pressed case KEY_CHANGE: // Example_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break;
// Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: MRK IT
Example_MessageMSGCB( MSGpkt ); break;
// Received whenever the device changes state in the network case ZDO_STATE_CHANGE: Example_NwkState =(devStates_t)(MSGpkt->hdr.status); if ( (Example_NwkState ==DEV_ZB_COORD) || (Example_NwkState ==DEV_ROUTER) || (Example_NwkState ==DEV_END_DEVICE) ) { // Start sending the periodic message in a regular interval. osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT ); } else { // Device is no longer in the network } break;
default: break; }
// Release the memory osal_msg_deallocate( (uint8 *)MSGpkt );
// Next - if one is available MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); }
// Send a message out - This event is generated by a timer // (setup in Example_Init()). if ( events & EXAMPLE_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message Example_SendPeriodicMessage();
// Setup to send message again in normal period (+a little jitter) osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, (EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT +(osal_rand() & 0x00FF)) );
// return unprocessed events return (events ^EXAMPLE_SEND_PERIODIC_MSG_EVT); MRK IT
} // Discard unknown events return 0; }
void Example_HandleKeys( uint8 shift, uint8 keys ) { if ( keys & HAL_KEY_SW_2 ) { /* This key sends the Flash Command is sent to Group 1. * This device will not receive the Flash Command from this * device (even if it belongs to group 1). */ // Example_SendFlashMessage( EXAMPLE_FLASH_DURATION ); }
if ( keys & HAL_KEY_SW_1 ) { /* The Flashr Command is sent to Group 1. * This key toggles this device in and out of group 1. * If this device doesn't belong to group 1, this application * will not receive the Flash command sent to group 1. */ aps_Group_t *grp; grp =aps_FindGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); if ( grp ) { // Remove from the group //aps_RemoveGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); } else { // Add to the flash group //aps_AddGroup( EXAMPLE_ENDPOINT, &Example_Group ); } } } void Example_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { uint8 buf[11]; uint8 d1,d2,d3,d4,d5; uint8 buf2[3]; buf2[0]=0x0d; buf2[1]=0x0a;
switch ( pkt->clusterId ) { uint8 seqnb; MRK IT
/******* FORCE SENSOR **********/ case EXAMPLE_PERIODIC_CLUSTERID1: HalLedSet (HAL_LED_1, HAL_LED_MODE_OFF); seqnb =pkt->cmd.TransSeqNumber; d1=pkt->cmd.Data[0];
// This is the Endpoint/Interface description. It is defined here, but // filled-in in Example_Init(). Another way to go would be to fill // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t Example_epDesc; uint8 *data; byte *wdata; uint8 Example_TaskID; // Task ID for internal task/event processing // This variable will be received when MRK IT
// Example_Init() is called. devStates_t Example_NwkState;
uint8 Example_TransID; // This is the unique message ID (counter)
// Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main().
#if defined ( SOFT_START ) // The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START // SOFT_START is a compile option that allows the device to start // as a coordinator if one isn't found. MRK IT
// We are looking at a jumper (defined in ExampleHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJ umper() ) zgDeviceLogicalType =ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType =ZG_DEVICETYPE_ROUTER; #endif // SOFT_START
#if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif
// Setup for the periodic message's destination address // Broadcast to everyone Example_Periodic_DstAddr.addrMode =(afAddrMode_t)AddrBroadcast; Example_Periodic_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Periodic_DstAddr.addr.shortAddr =0xFFFF;
// Setup for the flash command's destination address - Group 1 Example_Flash_DstAddr.addrMode =(afAddrMode_t)afAddrGroup; Example_Flash_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Flash_DstAddr.addr.shortAddr =EXAMPLE_FLASH_GROUP;
// Fill out the endpoint description. Example_epDesc.endPoint =EXAMPLE_ENDPOINT; Example_epDesc.task_id =&Example_TaskID; Example_epDesc.simpleDesc =(SimpleDescriptionFormat_t *)&Example_SimpleDesc; Example_epDesc.latencyReq =noLatencyReqs;
// Register the endpoint description with the AF afRegister( &Example_epDesc );
// Register for all key events - This app will handle all key events RegisterForKeys( Example_TaskID );
// By default, all devices start out in Group 1 Example_Group.ID =0x0001; osal_memcpy( Example_Group.name, "Group 1", 7 ); aps_AddGroup( EXAMPLE_ENDPOINT, &Example_Group );
if ( events & SYS_EVENT_MSG ) { MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a key is pressed case KEY_CHANGE: // Example_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)- >keys ); break;
// Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: Example_MessageMSGCB( MSGpkt ); MRK IT
break;
// Received whenever the device changes state in the network case ZDO_STATE_CHANGE: Example_NwkState =(devStates_t)(MSGpkt->hdr.status); if ( (Example_NwkState ==DEV_ZB_COORD) || (Example_NwkState ==DEV_ROUTER) || (Example_NwkState ==DEV_END_DEVICE) ) { // Start sending the periodic message in a regular interval. osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT ); } else { // Device is no longer in the network } break;
default: break; }
// Release the memory osal_msg_deallocate( (uint8 *)MSGpkt );
// Next - if one is available MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); }
// Send a message out - This event is generated by a timer // (setup in Example_Init()). if ( events & EXAMPLE_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message Example_SendPeriodicMessage();
// Setup to send message again in normal period (+a little jitter) osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, (EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT +(osal_rand() & 0x00FF)) ); MRK IT
void Example_HandleKeys( uint8 shift, uint8 keys ) { if ( keys & HAL_KEY_SW_2 ) { /* This key sends the Flash Command is sent to Group 1. * This device will not receive the Flash Command from this * device (even if it belongs to group 1). */ // Example_SendFlashMessage( EXAMPLE_FLASH_DURATION ); }
if ( keys & HAL_KEY_SW_1 ) {
aps_Group_t *grp; grp =aps_FindGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); if ( grp ) { // Remove from the group //aps_RemoveGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); } else { // Add to the flash group //aps_AddGroup( EXAMPLE_ENDPOINT, &Example_Group ); } } }
RESULT: Thus the program for ADC functioning is performed on Zigbee modules. MRK IT
LIGHT SENSOR USING ZIGBEE AIM: To write a program for sensing light intensity using LDR in Zigbee. APPARATUS REQUIRED: SOFTWARE: Zigbee modules (2), Debugger module (1), RS232 cable (1), ZRF connector (1). HARDWARE: Smart RF Flash programmer, WinXTalk. OPERATING SYSTEM: Windows XP. THEORY: Vi sensor modules are most compatible, reliable and very easy to use for sensing and controlling applications. Light sensor is designed with two pin LDR ( Light Dependent Resistor). The resistor value of the LDR varies with the luminous around it. PROCEDURE: Open Smart RF programmer and connect the RF modules to the debugger using RF connector. The details of the chip is read and displayed in the window as soon as the connection is established. Select Retain IEEE address when reprogramming the chip. Click on the Read IEEE button to read the IEEE address of the module. PROGRAM FOR COORDINATOR: #include "OSAL.h" #include "ZGlobals.h" #include "AF.h" #include "aps_groups.h" #include "ZDApp.h"
uint8 s; uint8 buffer1=0; // This list should be filled with Application specific Cluster IDs. const cId_t Example_ClusterList[EXAMPLE_MAX_CLUSTERS] = { EXAMPLE_PERIODIC_CLUSTERID, EXAMPLE_FLASH_CLUSTERID, EXAMPLE_PERIODIC_CLUSTERID1, EXAMPLE_PERIODIC_CLUSTERID2, EXAMPLE_PERIODIC_CLUSTERID3, EXAMPLE_PERIODIC_CLUSTERID4, EXAMPLE_PERIODIC_CLUSTERID5, EXAMPLE_PERIODIC_CLUSTERID6, EXAMPLE_PERIODIC_CLUSTERID7 };
// This is the Endpoint/Interface description. It is defined here, but // filled-in in Example_Init(). Another way to go would be to fill // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t Example_epDesc; uint8 *data; byte *wdata; uint8 Example_TaskID; // Task ID for internal task/event processing // This variable will be received when // Example_Init() is called. devStates_t Example_NwkState;
MRK IT
uint8 Example_TransID; // This is the unique message ID (counter)
* @fn Example_Init * * @brief Initialization function for the Generic App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none void Example_Init( uint8 task_id ) { Example_TaskID =task_id; Example_NwkState =DEV_INIT; Example_TransID =0; Example_Seqnb =Example_Seqnb1 =0x00;
// Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. MRK IT
// If the hardware is other parts of the device add it in main().
#if defined ( SOFT_START ) // The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START // SOFT_START is a compile option that allows the device to start // as a coordinator if one isn't found. // We are looking at a jumper (defined in ExampleHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. if ( readCoordinatorJ umper() ) zgDeviceLogicalType =ZG_DEVICETYPE_COORDINATOR; else zgDeviceLogicalType =ZG_DEVICETYPE_ROUTER; #endif // SOFT_START
#if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif
// Setup for the periodic message's destination address // Broadcast to everyone Example_Periodic_DstAddr.addrMode =(afAddrMode_t)AddrBroadcast; Example_Periodic_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Periodic_DstAddr.addr.shortAddr =0xFFFF;
// Setup for the flash command's destination address - Group 1 Example_Flash_DstAddr.addrMode =(afAddrMode_t)afAddrGroup; Example_Flash_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Flash_DstAddr.addr.shortAddr =EXAMPLE_FLASH_GROUP;
// Fill out the endpoint description. Example_epDesc.endPoint =EXAMPLE_ENDPOINT; Example_epDesc.task_id =&Example_TaskID; Example_epDesc.simpleDesc =(SimpleDescriptionFormat_t *)&Example_SimpleDesc; Example_epDesc.latencyReq =noLatencyReqs;
// Register the endpoint description with the AF afRegister( &Example_epDesc );
// Register for all key events - This app will handle all key events RegisterForKeys( Example_TaskID );
// By default, all devices start out in Group 1 Example_Group.ID =0x0001; osal_memcpy( Example_Group.name, "Group 1", 7 ); MRK IT
if ( events & SYS_EVENT_MSG ) { MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a key is pressed case KEY_CHANGE: // Example_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break;
// Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: Example_MessageMSGCB( MSGpkt ); break;
// Received whenever the device changes state in the network MRK IT
case ZDO_STATE_CHANGE: Example_NwkState =(devStates_t)(MSGpkt->hdr.status); if ( (Example_NwkState ==DEV_ZB_COORD) || (Example_NwkState ==DEV_ROUTER) || (Example_NwkState ==DEV_END_DEVICE) ) { // Start sending the periodic message in a regular interval. osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT ); } else { // Device is no longer in the network } break;
default: break; }
// Release the memory osal_msg_deallocate( (uint8 *)MSGpkt );
// Next - if one is available MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); }
// Send a message out - This event is generated by a timer // (setup in Example_Init()). if ( events & EXAMPLE_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message Example_SendPeriodicMessage();
// Setup to send message again in normal period (+a little jitter) osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, (EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT +(osal_rand() & 0x00FF)) );
void Example_HandleKeys( uint8 shift, uint8 keys ) { if ( keys & HAL_KEY_SW_2 ) { /* This key sends the Flash Command is sent to Group 1. * This device will not receive the Flash Command from this * device (even if it belongs to group 1). */ // Example_SendFlashMessage( EXAMPLE_FLASH_DURATION ); }
if ( keys & HAL_KEY_SW_1 ) { /* The Flashr Command is sent to Group 1. * This key toggles this device in and out of group 1. * If this device doesn't belong to group 1, this application * will not receive the Flash command sent to group 1. */ aps_Group_t *grp; grp =aps_FindGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); if ( grp ) { // Remove from the group //aps_RemoveGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); } else { // Add to the flash group //aps_AddGroup( EXAMPLE_ENDPOINT, &Example_Group ); } } } void Example_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { uint8 buf[11]; uint8 d1,d2,d3,d4,d5; uint8 buf2[3]; buf2[0]=0x0d; buf2[1]=0x0a;
switch ( pkt->clusterId ) { uint8 seqnb;
/******* FORCE SENSOR **********/ case EXAMPLE_PERIODIC_CLUSTERID1: HalLedSet (HAL_LED_1, HAL_LED_MODE_OFF); MRK IT
// This is the Endpoint/Interface description. It is defined here, but // filled-in in Example_Init(). Another way to go would be to fill // in the structure here and make it a "const" (in code space). The // way it's defined in this sample app it is define in RAM. endPointDesc_t Example_epDesc; uint8 *data; byte *wdata; uint8 Example_TaskID; // Task ID for internal task/event processing // This variable will be received when // Example_Init() is called. devStates_t Example_NwkState;
MRK IT
uint8 Example_TransID; // This is the unique message ID (counter)
// Device hardware initialization can be added here or in main() (Zmain.c). // If the hardware is application specific - add it here. // If the hardware is other parts of the device add it in main().
#if defined ( SOFT_START ) // The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START // SOFT_START is a compile option that allows the device to start // as a coordinator if one isn't found. // We are looking at a jumper (defined in ExampleHw.c) to be jumpered // together - if they are - we will start up a coordinator. Otherwise, // the device will start as a router. MRK IT
#if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START is a compile option that will surpress ZDApp // from starting the device and wait for the application to // start the device. ZDOInitDevice(0); #endif
// Setup for the periodic message's destination address // Broadcast to everyone Example_Periodic_DstAddr.addrMode =(afAddrMode_t)AddrBroadcast; Example_Periodic_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Periodic_DstAddr.addr.shortAddr =0xFFFF;
// Setup for the flash command's destination address - Group 1 Example_Flash_DstAddr.addrMode =(afAddrMode_t)afAddrGroup; Example_Flash_DstAddr.endPoint =EXAMPLE_ENDPOINT; Example_Flash_DstAddr.addr.shortAddr =EXAMPLE_FLASH_GROUP;
// Fill out the endpoint description. Example_epDesc.endPoint =EXAMPLE_ENDPOINT; Example_epDesc.task_id =&Example_TaskID; Example_epDesc.simpleDesc =(SimpleDescriptionFormat_t *)&Example_SimpleDesc; Example_epDesc.latencyReq =noLatencyReqs;
// Register the endpoint description with the AF afRegister( &Example_epDesc );
// Register for all key events - This app will handle all key events RegisterForKeys( Example_TaskID );
// By default, all devices start out in Group 1 Example_Group.ID =0x0001; osal_memcpy( Example_Group.name, "Group 1", 7 ); aps_AddGroup( EXAMPLE_ENDPOINT, &Example_Group );
if ( events & SYS_EVENT_MSG ) { MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { // Received when a key is pressed case KEY_CHANGE: // Example_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)- >keys ); break;
// Received when a messages is received (OTA) for this endpoint case AF_INCOMING_MSG_CMD: Example_MessageMSGCB( MSGpkt ); break;
// Received whenever the device changes state in the network MRK IT
case ZDO_STATE_CHANGE: Example_NwkState =(devStates_t)(MSGpkt->hdr.status); if ( (Example_NwkState ==DEV_ZB_COORD) || (Example_NwkState ==DEV_ROUTER) || (Example_NwkState ==DEV_END_DEVICE) ) { // Start sending the periodic message in a regular interval. osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT ); } else { // Device is no longer in the network } break;
default: break; }
// Release the memory osal_msg_deallocate( (uint8 *)MSGpkt );
// Next - if one is available MSGpkt =(afIncomingMSGPacket_t *)osal_msg_receive( Example_TaskID ); }
// Send a message out - This event is generated by a timer // (setup in Example_Init()). if ( events & EXAMPLE_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message Example_SendPeriodicMessage();
// Setup to send message again in normal period (+a little jitter) osal_start_timerEx( Example_TaskID, EXAMPLE_SEND_PERIODIC_MSG_EVT, (EXAMPLE_SEND_PERIODIC_MSG_TIMEOUT +(osal_rand() & 0x00FF)) );
// return unprocessed events return (events ^EXAMPLE_SEND_PERIODIC_MSG_EVT); MRK IT
}
// Discard unknown events return 0; }
void Example_HandleKeys( uint8 shift, uint8 keys ) { if ( keys & HAL_KEY_SW_2 ) { /* This key sends the Flash Command is sent to Group 1. * This device will not receive the Flash Command from this * device (even if it belongs to group 1). */ // Example_SendFlashMessage( EXAMPLE_FLASH_DURATION ); }
if ( keys & HAL_KEY_SW_1 ) {
aps_Group_t *grp; grp =aps_FindGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); if ( grp ) { // Remove from the group //aps_RemoveGroup( EXAMPLE_ENDPOINT, EXAMPLE_FLASH_GROUP ); } else { // Add to the flash group //aps_AddGroup( EXAMPLE_ENDPOINT, &Example_Group ); } } }
RESULT: Thus the intensity of light is sensed using LDR in Zigbee.
MRK IT
DESIGN AND TESTING OF TRAFFIC LIGHT CONTROLLER ON FPGA BOARG USING VERILOG CODE AIM: To design a traffic light controller on FPGA board using verilog codes. APPARATUS REQUIRED: * Xilinx ISE 9.1 * FPGA kit * FRC cable *AC adapter, LPT cable. THEORY: In this program, a traffic light control is designed using verilog codes in FPGA board. Various states are used to control traffic. In first state, the red signal of vehicle path is maintained high to allow the pedestrians for the usage of road. In next state, the entire pedestrian path is maintained high. The green signal of one path is maintained high for certain time and after some time the yellow light is at high state alerting the users that the red signal will be initiated at their path. Red signal is at high state at that path and at the same time green signal of another path is at high state and the entire states will be repeated. PROCEDURE: Click on the Xilinx 9.1 and open new project. Create new source and write the necessary codes. Check syntax and click new source in process window and open implement constraints file. Open .ucf file and assign pin packages Perform implement design and from the generate program file select configure device. Switch on the kit and open IMPACT and download the bit file and verify the output. PROGRAM: Behavioral Modeling: module traffic(clk, reset, p1, p2, p3, p4, pt); input clk; MRK IT
input reset; output [4:0] p1; // d5,d4,d3,d2,d1 output [4:0] p2; // d10,d9,d8,d7,d6 output [4:0] p3; // d15,d14,d13,d12,d11 output [4:0] p4; // d20,d19,d18,d17,d16 output [3:0] pt; // dl1,dl2,dl3,dl4,dl5,dl6,dl7,dl8 (Pedestrain) reg [4:0] p1; reg [4:0] p2; reg [4:0] p3; reg [4:0] p4; reg [3:0] pt; reg [31:0] sig; always @ (posedge clk or negedge reset) begin if (reset ==1'b0) begin p1 <=5'b00100; p2 <=5'b00100; p3 <=5'b00100; p4 <=5'b00100; pt <=4'b1111; sig <=8'h00000000; end else begin sig <=sig +1; case (sig[29:24]) 6'b000000 : begin MRK IT
p1 <=5'b10011; // d5,d4,d3,d2,d1 (Green) p2 <=5'b00100; p3 <=5'b00100; p4 <=5'b00100; pt <=4'b1111; end 6'b000100 : begin p1 <=5'b01000; //Yellow p2 <=5'b00100; p3 <=5'b00100; p4 <=5'b00100; pt <=4'b1111; end 6'b001000 : begin p1 <=5'b00100; // d10,d9,d8,d7,d6 p2 <=5'b10011; //Green p3 <=5'b00100; p4 <=5'b00100; pt <=4'b1111; end 6'b001100 : begin p1 <=5'b00100; p2 <=5'b01000; //Yellow p3 <=5'b00100; p4 <=5'b00100; pt <=4'b1111; MRK IT
end 6'b010000 : begin p1 <=5'b00100; // d15,d14,d13,d12,d11 p2 <=5'b00100; p3 <=5'b10011; //Green p4 <=5'b00100; pt <=4'b1111; end 6'b010100 : begin p1 <=5'b00100; p2 <=5'b00100; p3 <=5'b01000; //yellow p4 <=5'b00100; pt <=4'b1111; end 6'b011000 : begin p1 <=5'b00100; // d20,d19,d18,d17,d16 p2 <=5'b00100; p3 <=5'b00100; p4 <=5'b10011; //Green pt <=4'b1111; end 6'b011100 : begin p1 <=5'b00100; p2 <=5'b00100; p3 <=5'b00100; MRK IT
p4 <=5'b01000; //Yellow pt <=4'b1111; end 6'b100000 : begin p1 <=5'b00100; // dl1,dl2,dl3,dl4,dl5,dl6,dl7,dl8 p2 <=5'b00100; p3 <=5'b00100; p4 <=5'b00100; pt <=4'b0000; //Pedestrain end
6'b100100 : sig <=8'h00000000; default : begin end endcase end end endmodule
RESULT: Thus the traffic light controller on FPGA board is designed using verilog code and the output is verified.
MRK IT
PERFORMANCE CHARACTERISTICS OF ARM7 AND FPGA AIM: To analyze the performance of FPGA with ARM7 using serial communication. APPARATUS REQUIRED: HARDWARE: RS232 cable, Parallel port, FPGA, ARM7 kit. SOFTWARE: IAR Embedded systems, , Xilinx IDE 9.1 OPERATING SYSTEM: Windows XP. PROCEDURE FOR ARM 7: FOR CREATING NEW PROJ ECT: Open IAR embedded workbench To create a new project, choose project and select create new project. Give a file name for the project. Choose FILE menu and select NEW file. Edit the application code in C language. To save the C file choose file and then select Save As and save the file with the extension of .c [filename.c]. In the workspace window, select the file name and then right click on the file, choose Add and Add filename.c. Then choose options on the same workspace window. Choose Device as NXP NXPLPC2148. Choose Linker in the category and select the override default. In that menu, choose <filename.hex> Select others output format as Intel extended. Choose config menu to select override default. In that box, choose the path IAR systems embedded workbench 4.0 kickstart ARM examples NXP LPC214X IAR-LPC-214X ADC configuration flash.xcl. MRK IT
Right click on the workspace for rebuilding the program. FOR DOWNLOADING THE PROGRAM: In step 1 choose COM Port COM 1 Baud rate 9600 Device LPC 2148 Interface None Oscillator frequency 12MHz In step 2 select Erase blocks used by Hex file; In step 3 browse the hex file. In step 4 select Verify after programming. Then click the Start button. PROCEDURE FOR XILINX: * Click on the Xilinx 9.1 and open the window create new source * Write the necessary codes and synthesis the program to verify the syntax. * Open synthesis implementation and assign the pin packages. * Implement design and generate program file. * Switch on the kit and open IMPACT and download the bit file and verify the output. PROGRAM: LED PROGRAM FOR ARM 7 #include<iolpc2148.h> void LPC2148PLLInit(void); unsigned int i; void delay_ms() { MRK IT
int i,j; for(i=0;i<0xff;i++) for(j=0;j<0xff;j++); } void main() { PINSEL0 =0x00000000; // PINSEL(0,1,2) =0 configures pins as GPIO PINSEL1 =0x00000000; // (probably not necessary: PINSELs default to zero) PINSEL2 =0x00000000; // except P0.24, which doesn't exist on LPC2148 IO0DIR =0xFFFFFFFF; IO1DIR =0x00ff0000; // only P1.16 to p1.23 pin will be configured as Output Pin. IO0CLR =0xFFFF0000; while(1) { for(i=0;i<5;i++) { IO1SET=0x00ff0000; delay_ms(); IO1CLR=0x00ff0000; delay_ms(); }
for(i=0x00;i<0x08;i++) { IO1SET=0x00010000 <<i; delay_ms(); MRK IT
IO1CLR=0x00010000 <<i; delay_ms(); if(i==0x07) continue; } delay_ms(); } } void LPC2148PLLInit(void) { int loop_ctr; /* Configure PLL0, which determines the CPU clock */ PLLCFG =0x00000024; /* Use PLL values of M =4 and P =2 */ PLLCON_bit.PLLE =1; /* Set the PLL Enable bit */ PLLFEED =0xAA; /* Write to the PLL Feed register */ PLLFEED =0x55; loop_ctr =10000; /* Wait for the PLL to lock into the new frequency */ while (((PLLSTAT_bit.PLOCK) ==0) && (loop_ctr >0)) { loop_ctr--; } PLLCON_bit.PLLC =1; /* Connect the PLL */ PLLFEED =0xAA; /* Write to the PLL Feed register */ MRK IT
PLLFEED =0x55; // VPBDIV =0x00000001; /* Set the VPB frequency to one-half of the CPU clock */ } VHDL PROGRAM FOR FPGA library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity abc is Port ( RESET : in STD_LOGIC; CLK_4M : in STD_LOGIC; COUNTER : out STD_LOGIC_VECTOR (3 downto 0)); end abc; architecture Behavioral of abc is SIGNAL CLKDIV : STD_LOGIC_VECTOR(30 DOWNTO 0); SIGNAL CNTR : STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL en0,en1,en2,en3 : STD_LOGIC; begin PROCESS(RESET,CLK_4M) BEGIN IF(RESET ='1') THEN CLKDIV <=(OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M ='1')THEN CLKDIV <=CLKDIV +'1'; MRK IT
END IF; END PROCESS; PROCESS(RESET,CLK_4M,clkdiv) BEGIN IF(RESET ='1') THEN en1 <='0'; en2 <='0'; ELSIF(CLK_4M'EVENT AND CLK_4M ='1')THEN en1 <=CLKDIV (20); en2 <=en1; END IF; END PROCESS; en0 <=en1 and (not en2); PROCESS(RESET,CLK_4M,en0) BEGIN IF(RESET ='1') THEN CNTR <=(OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M ='1')THEN IF(en0 ='1')THEN CNTR <=CNTR +'1'; END IF; END IF; END PROCESS; COUNTER <=CNTR; MRK IT