0% found this document useful (0 votes)
9 views12 pages

Lab4 em

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Lab4 em

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Name: Mentalla hussein

sedik
ID: 2100872
Department: CSE
LAB4
1.The state of the LEDs.
2. The values of the GPIOF registers such as (DATA, DIR, AFSEL, …
etc.), UART registers, and UART serial window.
3.Code
"include"tm4c123gh6pm.h#

>include<string.h#

>include<stdint.h#

define CR 0x0D#

{void UART_Init(void)

;SYSCTL_RCGCUART_R|=0x0001

;SYSCTL_RCGCGPIO_R|=0x0001

;UARTx_CTL_R&=~0x0001

;UART0_IBRD_R=0X68

;UART0_FBRD_R=0X0B

;UART0_LCRH_R=0x0070
;UARTx_CTL_R|=0X0301

;GPIO_PORTA_AFSEL_R|=0x03

;GPIO_PORTA_PCTL_R=GPIO_PORTA_PCTL_R&0xFFFFFF00+0X00000011

;GPIO_PORTA_DEN_R|=0x03

;GPIO_PORTA_AMSEL_R&=~0x03

{void SysTick_Wait(uint32_t delay)

;NVIC_ST_CTRL_R = 0

;NVIC_ST_RELOAD_R = delay-1

;NVIC_ST_CURRENT_R = 0

;NVIC_ST_CTRL_R = 0x00000005

}{while((NVIC_ST_CTRL_R&0x00010000)==0)

{void SysTick_Wait1s(uint32_t delay)

;unsigned long i

{for(i=0; i<delay; i++)

SysTick_Wait(160000); // wait 10ms

{void systemInit(void)

;SYSCTL_RCGCGPIO_R |=0x20

;while((SYSCTL_PRGPIO_R&0x20)==0)

;GPIO_PORTF_LOCK_R=SYSCTL_PRGPIO_R
;GPIO_PORTF_CR_R|=0x0E

;GPIO_PORTF_AMSEL_R&=~0x0E

;GPIO_PORTF_AFSEL_R&=~0x0E

;GPIO_PORTF_PCTL_R &=~0x0000FFF0

;GPIO_PORTF_DIR_R|=0x0E

;GPIO_PORTF_DEN_R|=0x0E

;GPIO_PORTF_DATA_R &=~0x0E

read uart data//

{)(char UART_InChar

while((UART0_FR_R&0x10)!=0);//RX EM

;return (char) UART0_DR_R

write uart data//

{void UART_outChar(char data)

while((UART0_FR_R&0x20)!=0);//TX FULL

;UART0_DR_R=data

void RGB_setOutput(unsigned char data)

;GPIO_PORTF_DATA_R|=data

void RGB_clearOutput(unsigned char data)

;GPIO_PORTF_DATA_R&=data

}
{void UART_outString(char *ar)

{while(*ar)

;UART_outChar(*ar)

;++ar

{void getCommand(char* command, int len)

;int i

;char character

{for(i=0,i<len,i++)

;)(character=UART_InChar

{if(character!=CR)

;command[i]=character

};UART_outChar(character)

;else if(character==CR||i==len) break

{)(int main

;const int len=2

;}0{=char Command[len]

;)(UART_Init

;)(systemInit
{)1(while

;UART_outString("Enter:\n")

;getCommand(command, len)

;RGB_clearOutput(~0x0E)

{if(strcmp(Command,"A")==0)

;RGB_clearOutput(~0x0E)

SysTick_Wait1s(6000); //1m

;RGB_setOutput(0x02)

;memset(Command,0,len)

{else if(strcmp(Command,"B")==0)

;RGB_clearOutput(~0x0E)

SysTick_Wait1s(3000); //0.5m

;RGB_setOutput(0x04

;memset(Command,0,len)

{else if(strcmp(Command,"D)==0)

;RGB_clearOutput(~0x0E)

SysTick_Wait1s(12000); //2m

;RGB_setOutput(0x08)

;memset(Command,0,len)

{else

;RGB_clearOutput(~0x0E)
}

UART_outString("\n")

You might also like