Skip to content

Commit

Permalink
Uart init updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mariamelsaayed committed May 3, 2019
2 parents 028b2a5 + 8ec6554 commit a87123f
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 31 deletions.
10 changes: 10 additions & 0 deletions Tivac1/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ void SystemInit()
{
}

void Delay(uint16_t i){
uint16_t time;
time = 145448; // 0.1sec
for(uint16_t j=0; j<i; j++){
while(time){
time--;
}
}
}

int main (void)
{
return 0;
Expand Down
81 changes: 81 additions & 0 deletions Tivac1/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,84 @@ void Port_SetPinDirection (uint8_t port_index, uint8_t pins_mask, Port_PinDirect
}


void Port_AnalogOrDigital (uint8_t port_index, uint8_t pins_mask, AnalogOrDigital pins_type){
switch (port_index)
{
case PA:
if(pins_type == Analog){
GPIO_PORTA_AMSEL_R |= (pins_mask);
GPIO_PORTA_DEN_R &= ~(pins_mask);
}

else if (pins_type == Digital){
GPIO_PORTA_AMSEL_R &= ~(pins_mask);
GPIO_PORTA_DEN_R |= (pins_mask);
}

break;
case PB:
if(pins_type == Analog){
GPIO_PORTB_AMSEL_R |= (pins_mask);
GPIO_PORTB_DEN_R &= ~(pins_mask);
}

else if (pins_type == Digital){
GPIO_PORTB_AMSEL_R &= ~(pins_mask);
GPIO_PORTB_DEN_R |= (pins_mask);
}

break;
case PC:
if(pins_type == Analog){
GPIO_PORTC_AMSEL_R |= (pins_mask);
GPIO_PORTC_DEN_R &= ~(pins_mask);
}

else if (pins_type == Digital){
GPIO_PORTC_AMSEL_R &= ~(pins_mask);
GPIO_PORTC_DEN_R |= (pins_mask);
}

break;
case PD:
if(pins_type == Analog){
GPIO_PORTD_AMSEL_R |= (pins_mask);
GPIO_PORTD_DEN_R &= ~(pins_mask);
}

else if (pins_type == Digital){
GPIO_PORTD_AMSEL_R &= ~(pins_mask);
GPIO_PORTD_DEN_R |= (pins_mask);
}

break;
case PE:
if(pins_type == Analog){
GPIO_PORTE_AMSEL_R |= (pins_mask);
GPIO_PORTE_DEN_R &= ~(pins_mask);
}

else if (pins_type == Digital){
GPIO_PORTE_AMSEL_R &= ~(pins_mask);
GPIO_PORTE_DEN_R |= (pins_mask);
}

break;
case PF:
if(pins_type == Analog){
GPIO_PORTF_AMSEL_R |= (pins_mask);
GPIO_PORTF_DEN_R &= ~(pins_mask);
}

else if (pins_type == Digital){
GPIO_PORTF_AMSEL_R &= ~(pins_mask);
GPIO_PORTF_DEN_R |= (pins_mask);
}

break;
}
}

/*void Port_AlternateFunction (uint8_t port_index, uint8_t pins_mask, uint8_t enable, uint32_t pctl_mask){
}*/
23 changes: 23 additions & 0 deletions Tivac1/systick.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "systick.h"
#include "tm4c123gh6pm.h"
#include "std_types.h"

void systick_init(void){
NVIC_ST_CTRL_R &= ~NVIC_ST_CTRL_ENABLE;
NVIC_ST_RELOAD_R = NVIC_ST_RELOAD_M;
NVIC_ST_CURRENT_R = NVIC_ST_CURRENT_S;
NVIC_ST_CTRL_R |= (NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE);

}

void systick_wait1ms(void){
NVIC_ST_RELOAD_R = 16000 - 1;
NVIC_ST_CURRENT_R = 0;
while((NVIC_ST_CTRL_R&NVIC_ST_CTRL_COUNT) != NVIC_ST_CTRL_COUNT);
}

void delay(uint16_t i){
for(uint16_t j=0; j<i; j++){
systick_wait1ms();
}
}
10 changes: 10 additions & 0 deletions Tivac1/systick.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __SYSTICK_H__
#define __SYSTICK_H__

void systick_init(void);

void systick_wait1ms(void);

void delay(uint16_t);

#endif // __SYSTICK_H__
5 changes: 5 additions & 0 deletions Tivac1/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ uint8_t UART0_Read (void)

return word;
}

void UART0_Write(uint8_t data){
while((UART0_FR_R&UART_FR_TXFF) != 0);
UART0_DR_R = data;
}
2 changes: 1 addition & 1 deletion Tivac1/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

uint8_t UART0_Read (void);


void UART0_Write(uint8_t data);


#endif
26 changes: 26 additions & 0 deletions Tivac2/adc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "adc.h"


void ADC0_SS3_Init (void)
{
SYSCTL_RCGCADC_R |= (1<<0); //enable ADC0 clock
ADC0_ACTSS_R &= ~(1<<SS_num); //disable sample sequncer during configuration
ADC0_EMUX_R = (ADC0_EMUX_R& ~(0xF<<SS_num*4)) | (trigger_select<<SS_num*4) ; //choosing the triggering method
ADC0_SSMUX3_R = 0x0; //input from channel 0 i.e PE3
ADC0_SSCTL3_R |= ( (ADC0_SSCTL3_TS0<<3) | (ADC0_SSCTL3_IE0<<2) | (ADC0_SSCTL3_END0<<1)); //configuring sample sequncer 3 control port
if(ADC0_SSCTL3_IE0 == 0x1)
{
ADC0_IM_R |= (1<<3);
NVIC_EN0_R |= (1<<17);
}
ADC0_ACTSS_R |= (1<<SS_num); //enable sample sequncer during configuration
}
void ADC_Init_Potentiometer (void)
{
ADC0_SS3_Init ();
Port_AnalogOrDigital (PORTE, 0X08, 0);
//Port_AlternateFunction (PORTE,0X08,1, uint32_t pctl_mask);
GPIO_PORTE_AFSEL_R|=0x08;


}
20 changes: 20 additions & 0 deletions Tivac2/adc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#ifndef ADC_H_
#define ADC_H_

#include "port.h"
#include "DIO.h"
#include "tm4c123gh6pm.h"
#include "std_types.h"

#define trigger_select 0x0F
#define SS_num 3
#define ADC0_SSCTL3_IE0 0x1
#define ADC0_SSCTL3_END0 0x1
#define ADC0_SSCTL3_TS0 0x1


void ADC0_SS3_Init (void);
void ADC_Init_Potentiometer (void);

#endif
77 changes: 48 additions & 29 deletions Tivac2/lcd.c
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
#include "lcd.h"

void LCD_IntegerToString ( uint16_t data, char* str)
void LCD_IntegerToString ( uint16_t data, char* str)
{ uint8_t temp;
uint8_t start;
uint8_t end;
int i = 0;
int i = 0;

/* Handle 0 explicitely, otherwise empty string is printed for 0 */
if (data == 0)
{
str[i++] = '0';
str[i] = '\0';
}
// Process individual digits
while (data != 0)
{
uint16_t rem = data % 10;
str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
data = data/10;
}
str[i] = '\0'; // Append string terminator
// Reverse the string
start = 0;
end = i -1;
while (start < end)
{
if (data == 0)
{
str[i++] = '0';
str[i] = '\0';
}

// Process individual digits
while (data != 0)
{
uint16_t rem = data % 10;
str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
data = data/10;
}
str[i] = '\0'; // Append string terminator

// Reverse the string
start = 0;
end = i -1;

while (start < end)
{
temp = *(str+start);
*(str+start) = *(str+end);
*(str+end) = temp;
start++;
end--;

start++;
end--;
}
}
}

void LCD_Init (void)
{
Expand All @@ -59,4 +59,23 @@ void LCD_DisplayString(const uint8_t *str)
{
LCD_SendData(str[i]);
}
}
}
void msdelay(uint32_t y)
{
unsigned long volatile t;
t= 1000*y;
while(t){t--;}
}
void LCD_sendCommand(uint8_t command){

DIO_WritePort(PORTA,RS,STD_LOW);
DIO_WritePort(PORTA,RW,STD_LOW);
msdelay(1);
DIO_WritePort(PORTA,E,STD_HIGH);
msdelay(1);
DIO_SetValuePort(PORTB,command);
msdelay(1);
DIO_WritePort(PORTA,E,STD_LOW);
msdelay(1);

}
12 changes: 12 additions & 0 deletions Tivac2/push_buttons.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "lcd.h"
void pushButtons_Init (void)
{
void Port_Init (PF);
void Port_SetPinDirection (PF, 0x11, PORT_PIN_IN);
void Port_AnalogOrDigital (PF,0x11, 1);
void Port_AlternateFunction (PF, 0x11, 0, 0x00);
void Port_SetPinPullUp (PF, 0x11, 1);


}
#endif
8 changes: 8 additions & 0 deletions Tivac2/push_buttons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef PushB_H_
#define PushB_H_

#include "tm4c123gh6pm.h"
#include "std_types.h"
#include "lcd.h"

void pushButtons_Init (void);
9 changes: 8 additions & 1 deletion Tivac2/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ void UART0_Init(void)
GPIO_PORTA_DEN_R |= 0x003;
GPIO_PORTA_AMSEL_R &= ~0x003;

}
}

uint8_t UART0_Read (void)
{
while((UART0_FR_R&0x0010)!=0);
return(UART0_DR_R&0xFF);

}

0 comments on commit a87123f

Please sign in to comment.