// RegisterDefinitionsForUART2Module #define UART2_CTL_R (*((volatile unsigned long*) 0x4000E030 )) #define UART2_IBRD_R (*((volatile unsigned long*) 0x4000E024 )) #define UART2_FBRD_R (*((volatile unsigned long*) 0x4000E028 )) #define UART2_LCRH_R (*((volatile unsigned long*) 0x4000E02C)) #define UART2_CC_R (*((volatile unsigned long*) 0x4000EFC8 )) #define UART2_FR_R (*((volatile unsigned long*) 0x4000E018 )) #define UART2_DR_R (*((volatile unsigned long*) 0x4000E000 )) #define SYSCTL_RCGCUART_R (*((volatile unsigned long*) 0x400FE618 )) #define SYSCTL_RCGCGPIO_R (*((volatile unsigned long*) 0x400FE608 )) #define GPIO_PORTD_LOCK_R (*((volatile unsigned long*) 0x40007520 )) #define GPIO_PORTD_CR_R (*((volatile unsigned long*) 0x40007524 )) #define GPIO_PORTD_AFSEL_R (*((volatile unsigned long*) 0x40007420 )) #define GPIO_PORTD_PCTL_R (*((volatile unsigned long*) 0x4000752C )) #define GPIO_PORTD_DEN_R (*((volatile unsigned long*) 0x4000751C )) unsigned char String1[5]; unsigned char String2[5]={0}; // Macros f o r i n i t i a l i z a t i o n and c o n f i g u r a t i o n o f UART2 #define UART2_CLK_EN 0x00000004 // Enable c l o c k f o r UART2 #define GPIO_PORTD_CLK_EN 0x00000008 // Enable c l o c k f o r GPIO PORTD #define GPIO_PORTD_UART2_CFG 0x000000C0 // Di g i t a l enabl e // Ac t ivat e a l t e r n a t e func t i onf o r PD6 and PD7 #define GPIO_PCTL_PD6_U2RX 0x01000000 // Conf igur e PD6 as U2RX #define GPIO_PCTL_PD7_U2TX 0x10000000 // Conf igur e PD7 as U2TX #define GPIO_PORTD_UNLOCK_CR 0x4C4F434B // Unlock Commit r e g i s t e r #define GPIO_PORTD_CR_EN 0x000000FF // Di sabl e wr i t e p r o t e c t i o n #define UART_CS_SysClk 0x00000000 // Use system as UART c l o c k #define UART_CS_PIOSC 0x00000005 // Use PIOSC as UART c l o c k #define UART_LCRH_WLEN8 0x00000060 // 8 b i t word l ength #define UART_LCRH_FEN 0x00000010 // Enable UART FIFOs #define UART_FR_TXFF 0x00000020 // UART Transmit FIFO Ful l #define UART_FR_RXFE 0x00000010 // UART Receive FIFO Empty #define UART_CTL_UARTEN 0x00000001 // Enable UART #define UART_LB_EN 0x00000080 // Use UART in Loopback mode #define GPIO_PORTF_DATA_R (*((volatile unsigned long*)0x400253FC)) #define GPIO_PORTF_DIR_R (*((volatile unsigned long*)0x40025400)) #define GPIO_PORTF_DEN_R (*((volatile unsigned long*)0x4002551C)) #define GPIO_PORTF_CLK_EN 0x20 #define GPIO_PORTF_PIN3_EN 0x0A #define LED_ON 0x08 #define LED_OFF ~(0x08) #define LED_ON1 0x02 #define LED_OFF1 ~(0x02) #define pass '4' #define pass1 '4' #define pass2 '5' #define pass3 '3' #define pass4 '0' #define pass8 '9' #define pass9 '0' #define pass10 '3' #define pass11 '1' #define pass12 '1' #define pass16 '4' #define pass17 '4' #define pass18 '5' #define pass19 '4' #define pass20 '7' #define pass24 '4' #define pass25 '4' #define pass26 '5' #define pass27 '2' #define pass28 '6' #define GPIO_PORTB_DATA_R *((volatile unsigned long *) 0x400053FC) #define GPIO_PORTB_DIR_R *((volatile unsigned long *) 0x40005400) #define GPIO_PORTB_DEN_R *((volatile unsigned long *) 0x4000551C) #define GPIO_PORTB_AFSEL_R *((volatile unsigned long *) 0x40005420) #define GPIO_PORTE_DATA_R *((volatile unsigned long *) 0x400240E0) #define GPIO_PORTE_DIR_R *((volatile unsigned long *) 0x40024400) #define GPIO_PORTE_DEN_R *((volatile unsigned long *) 0x4002451C) #define GPIO_PORTE_AFSEL_R *((volatile unsigned long *) 0x40024420) #define LCD_E_PIN 0x08 #define LCD_RW_PIN 0x10 #define LCD_RS_PIN 0x20 #define LCD_DATA_BUS GPIO_PORTB_DATA_R #define LCD_CONTROL_BUS GPIO_PORTE_DATA_R void LCD_Init (void); void LCD_Clear (void); void LCD_Send_Command (unsigned char command); void LCD_Send_Data (unsigned char data); void LCD_Goto_XY (unsigned char x, unsigned char y); void LCD_Send_String (char *ptr); #define TM_BASE 0x40031000 #define RCGC_TIMER_R (*(volatile unsigned long *)0x400FE604) #define RCGC2_GPIO_R (*(volatile unsigned long *)0x400FE108) #define CLOCK_GPIOF 0x00000020 #define SYS_CLOCK_FREQUENCY 16000000 #define GPTM_CONFIG_R *(volatile unsigned long *)(TM_BASE + 0x000) #define GPTM_TA_MODE_R *(volatile unsigned long *)(TM_BASE + 0x004) #define GPTM_CONTROL_R *(volatile unsigned long *)(TM_BASE + 0x00C) #define GPTM_INT_MASK_R *(volatile unsigned long *)(TM_BASE + 0x018) #define GPTM_INT_CLEAR_R *(volatile unsigned long *)(TM_BASE + 0x024) #define GPTM_TA_IL_R *(volatile unsigned long *)(TM_BASE + 0x028) #define GPTM_TA_MATCH_R *(volatile unsigned long *)(TM_BASE + 0x030) //#define GPIO_PORTC_AFSEL_R *(volatile unsigned long *)0x40006420 //#define GPIO_PORTC_PCTL_R *(volatile unsigned long *)0x4000652C //#define GPIO_PORTC_DEN_R *(volatile unsigned long *)0x4000651C #define GPIO_PORTF_AFSEL_R *(volatile unsigned long *)0x40025420 #define GPIO_PORTF_PCTL_R *(volatile unsigned long *)0x4002552C #define TIM_16_BIT_CONFIG 0x00000004 #define TIM_PERIODIC_MODE 0x00000002 #define TIM_A_ENABLE 0x00000001 #define TIM_PWM_MODE 0x0000000A #define TIM_CAPTURE_MODE 0x00000004 #define TIM_A_INTERVAL 16000 #define TIM_A_MATCH 14000 // User button connected to PF4 // (turn on different LEDs on falling edge of buttonm press) // IRQ 0 to 31 Set Enable Register #define NVIC_EN0_R (*(( volatile unsigned long *) 0xE000E100 )) // IRQ 0 to 31 Set Enable Register #define NVIC_PRI7_R (*(( volatile unsigned long *) 0xE000E41C )) #define GPIO_PORTF_PUR_R (*(( volatile unsigned long *) 0x40025510 )) #define GPIO_PORTF_IS_R (*(( volatile unsigned long *) 0x40025404 )) #define GPIO_PORTF_IBE_R (*(( volatile unsigned long *) 0x40025408 )) #define GPIO_PORTF_IEV_R (*(( volatile unsigned long *) 0x4002540C )) #define GPIO_PORTF_IM_R (*(( volatile unsigned long *) 0x40025410 )) #define GPIO_PORTF_ICR_R (*(( volatile unsigned long *) 0x4002541C )) #define NVIC_EN0_INT30 0x40000000 //interrupt 30 enable #define PORTF_CLK_EN 0x20 //CLock enable for Port f #define LEDs 0xE //Enable LEDs #define SW1 0x10 //Enable user switch SW1 #define INT_PF4 0x10 //interrupt at PF4 void EnableInterrupts ( void ) ; //Disable interrupts void DisableInterrupts ( void ) ; //Enable interrupts void Init_INT_GPIO ( void ) ; //I n i t i a l i z e GPIO and Interrupts //void WaitForInterrupt ( void ) ; volatile unsigned long i = 0; void Init_INT_GPIO(void){ volatile unsigned delay_clk; SYSCTL_RCGCGPIO_R |= PORTF_CLK_EN; //Enable clock for PORTF delay_clk = SYSCTL_RCGCGPIO_R; //dummy read to stable the clock //GPIO GPIO_PORTF_DEN_R |= (SW1|LEDs); //Enable digital I/O on PF4, PF3 - PF1 GPIO_PORTF_DIR_R = 0xE; //Make PF$ input and PF3 - PF1 output //GPIO_PORTF_PUR_R |= SW1; //Enable weak pull up on PF4 //INTERRUPT DisableInterrupts(); GPIO_PORTF_IS_R &= ~INT_PF4; //PF4 is edge sensitive GPIO_PORTF_IBE_R &= ~INT_PF4; //PF4 is not both edges GPIO_PORTF_IEV_R &= ~INT_PF4; //PF4 is falling edge GPIO_PORTF_ICR_R |= INT_PF4; //Clear interrupt flag for PF4 GPIO_PORTF_IM_R |= INT_PF4; //Enable interrupt on PF4 NVIC_PRI7_R = 0x00A00000; //Set PF4 priority 5 NVIC_EN0_R = NVIC_EN0_INT30; //Enable interrupt 30 in NVIC EnableInterrupts(); } void Timer1A_Init(void) { RCGC2_GPIO_R |= CLOCK_GPIOF; RCGC_TIMER_R |= 0x02; GPIO_PORTF_AFSEL_R |=0x00000004; GPIO_PORTF_PCTL_R |=0x00000700; GPIO_PORTF_DEN_R |=0x00000004; //GPIO_PORTC_AFSEL_R |=0x00000020; //GPIO_PORTC_PCTL_R |=0x00070000; //GPIO_PORTC_DEN_R |=0x00000020; GPTM_CONTROL_R &= ~(TIM_A_ENABLE); GPTM_CONFIG_R |= TIM_16_BIT_CONFIG; GPTM_TA_MODE_R |= TIM_PWM_MODE; GPTM_TA_MODE_R &= ~(TIM_CAPTURE_MODE); GPTM_TA_IL_R = TIM_A_INTERVAL; GPTM_TA_MATCH_R = TIM_A_MATCH; GPTM_CONTROL_R |= TIM_A_ENABLE; } // Function d e f i n i t i o n s unsigned char UART_Rx( void ) ; //void UART_Tx_String ( char *pt ) ; //void UART_Rx_String ( char *bufPt , unsigned short max) ; void Delay(volatile unsigned int delay); // I n t i a l i z e and c o n f i g u r e UART void UART_Init ( void ){ // Enable c l o c k f o r UART2 and GPIO Port D SYSCTL_RCGCUART_R |= UART2_CLK_EN; // Ac t ivat e UART2 SYSCTL_RCGCGPIO_R |= (GPIO_PORTD_CLK_EN+GPIO_PORTF_CLK_EN+0x12); // Ac t ivat e Port D // Conf i gur a t i on to use PD6 and PD7 as UART GPIO_PORTD_LOCK_R = GPIO_PORTD_UNLOCK_CR; // Unlock commit r e g i s t e r GPIO_PORTD_CR_R |= GPIO_PORTD_CR_EN; // Enable U2Tx on PD7 GPIO_PORTD_DEN_R |= GPIO_PORTD_UART2_CFG; // Enable d i g i t a l I /O on PD6 GPIO_PORTF_DEN_R |= (GPIO_PORTF_PIN3_EN+0x04); GPIO_PORTF_DIR_R |= GPIO_PORTF_PIN3_EN; GPIO_PORTD_AFSEL_R |= GPIO_PORTD_UART2_CFG; // Enable a l t . func . on PD6??7 GPIO_PORTD_PCTL_R |= (GPIO_PCTL_PD6_U2RX | GPIO_PCTL_PD7_U2TX) ; GPIO_PORTB_DIR_R |= 0xFF; GPIO_PORTB_DEN_R |= 0xFF; GPIO_PORTB_AFSEL_R &= ~0xFF; GPIO_PORTE_DIR_R |= 0x38; GPIO_PORTE_DEN_R |=0x38; GPIO_PORTE_AFSEL_R &= ~0x38; // Conf i guration of UART2 module UART2_CTL_R&=~UART_CTL_UARTEN; // Disable UART // IBRD = i n t (16 ,000 ,000 / (16 * 9600 )) = i n t ( 104.164) UART2_IBRD_R = 0x68 ; // FBRD = i n t ( 0 . 164 * 64 + 0 . 5 ) = 11 UART2_FBRD_R = 0x0B ; // 8??b i t word length , no pa r i t y bi t , one s top bi t , FIFOs enabl e UART2_LCRH_R = (UART_LCRH_WLEN8|UART_LCRH_FEN) ; UART2_CC_R = UART_CS_SysClk ; // Use system c l o c k as UART c l o c k //UART2_CTL_R |= UART_LB_EN; // Enable loopback mode UART2_CTL_R|= UART_CTL_UARTEN; // Enable UART2 } void LCD_Send_Command (unsigned char command) { LCD_DATA_BUS = command; LCD_CONTROL_BUS = 0; Delay(1); LCD_CONTROL_BUS |= LCD_E_PIN; Delay (1); LCD_CONTROL_BUS &= ~(LCD_E_PIN); Delay (4); } void LCD_Send_Data (unsigned char data) { LCD_DATA_BUS = data; LCD_CONTROL_BUS = LCD_RS_PIN; Delay (1); LCD_CONTROL_BUS |= LCD_E_PIN; Delay (1); LCD_CONTROL_BUS &= ~(LCD_E_PIN); Delay(4); } void servo(void) {int j; for( j=0;j<58500;j++){ GPTM_TA_MATCH_R =9000;} for( j=0;j<10;j++){ GPTM_TA_MATCH_R =15999;} } void LCD_Init (void) { LCD_CONTROL_BUS = 0; Delay (1500); LCD_Send_Command(0x38); LCD_Send_Command(0x10); LCD_Send_Command(0x0F); LCD_Send_Command(0x06); } void LCD_Clear (void) { LCD_Send_Command (0x01); Delay (170); LCD_Send_Command (0x02); Delay(170); } void LCD_Send_String (char *ptr) { while (*ptr) { LCD_Send_Data (*ptr); ptr++; } } void LCD_Goto_XY (unsigned char x, unsigned char y) { unsigned char row_start_address[] ={0x80, 0xC0}; LCD_Send_Command (row_start_address[y-1] + x-1); Delay (170); } void Delay (volatile unsigned int delay) { volatile unsigned int i ,j; for (i = 0; i