[ Eddie's Blog ]

Saturday, January 22, 2022

Sw1 Press [On] Red LED (w/ Video)

 


/*

    
Testing Board #1

*/

#include "TM4C123GH6PM.h"


int main(void)

{

   unsigned int state;

   SYSCTL->RCGCGPIO |= 0x20;   /* enable clock to GPIOF */

   GPIOF->LOCK = 0x4C4F434B;   // unlockGPIOCR register

   GPIOF->CR = 0x01;           // Enable GPIOPUR register enable to commit

   GPIOF->PUR |= 0x10;        // Enable Pull Up resistor PF4

   GPIOF->DIR |= 0x02;          //set PF1 as an output and PF4 as an input pin

   GPIOF->DEN |= 0x12;         // Enable PF1 and PF4 as a digital GPIO pins 


    while(1)

    {   

        state = GPIOF->DATA & 0x10;

        GPIOF->DATA = (~state>>3);    /* put it on red LED */

    }

}


Posted by evilmind5 at 12:28 AM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: Keil, LED, TIVA

Friday, January 21, 2022

Blinking Red LED (w/ Video)



 /* Defines boolean and integer data types */

#include <stdbool.h>

#include <stdint.h>

#include "inc/tm4c123gh6pm.h"


#define delay_value 100000000 // change blink speed here


int main(void)

{

/* Delay Loop variable */

volatile unsigned long ulLoop;

/* Enable the GPIO port that is used for the onboard LED */

SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;

/* Do a dummy read to insert a few cycles after peripheral enable */

ulLoop = SYSCTL_RCGC2_R;

/* Enable the GPIO pin for the LED (PF1)

* Set the direction as output, and enable the GPIO pin for

* digital function. Care is taken to not disrupt the

* operation of the JTAG pins on PC0-PC3 */

GPIO_PORTF_DIR_R |= 0x02;  //set PF1 as an output and PF4 as an input pin

GPIO_PORTF_DEN_R |= 0x02;

GPIO_PORTF_AFSEL_R = 0x00;

/* Loop forever */

while(1)

{

/* Turn on the LED */

GPIO_PORTF_DATA_R |= 0x02;

/* Delay for a 100ms */

for(ulLoop = 0; ulLoop < delay_value; ulLoop++)

{

}

/* Turn off the LED */

GPIO_PORTF_DATA_R &=~ 0x02; // &= ˜(0x02) <-- Incorrect

/* Delay for a 100ms */

for(ulLoop = 0; ulLoop < delay_value; ulLoop++)

{

}

}

}


Posted by evilmind5 at 11:57 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: Keil, LED, TIVA

Sunday, June 2, 2019

Simple Cooling System

// center of X-ohm potentiometer connected to PE3/AIN0
// bottom of X-ohm potentiometer connected to ground
// top of X-ohm potentiometer connected to +3.3V
#include <stdint.h>
#include <stdbool.h>
#include "ADCSWTrigger.h"
#include "tm4c123gh6pm.h"
#include "PLL.h"

#define GPIO_PORTF2             (*((volatile uint32_t *)0x40025010))

#define ON 1
#define OFF 0

void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void);  // Enable interrupts
long StartCritical (void);    // previous I bit, disable interrupts
void EndCritical(long sr);    // restore I bit to previous value
void WaitForInterrupt(void);  // low power mode

bool Light = OFF;

volatile uint32_t ADCvalue;
// This debug function initializes Timer0A to request interrupts
// at a 10 Hz frequency.  It is similar to FreqMeasure.c.
void Timer0A_Init10HzInt(void){
  volatile uint32_t delay;
  DisableInterrupts();
  // **** general initialization ****
  SYSCTL_RCGCTIMER_R |= 0x01;// activate timer0
  delay = SYSCTL_RCGCTIMER_R;          // allow time to finish activating
  TIMER0_CTL_R &= ~TIMER_CTL_TAEN; // disable timer0A during setup
  TIMER0_CFG_R = 0;                // configure for 32-bit timer mode
  // **** timer0A initialization ****
                                   // configure for periodic mode
  TIMER0_TAMR_R = TIMER_TAMR_TAMR_PERIOD;
  TIMER0_TAILR_R = 2499999;        // start value for 10 Hz interrupts
  TIMER0_IMR_R |= TIMER_IMR_TATOIM;// enable timeout (rollover) interrupt
  TIMER0_ICR_R = TIMER_ICR_TATOCINT;// clear timer0A timeout flag
  TIMER0_CTL_R |= TIMER_CTL_TAEN;  // enable timer0A 16-b, periodic, interrupts
  // **** interrupt initialization ****
                                   // Timer0A=priority 2
  NVIC_PRI4_R = (NVIC_PRI4_R&0x00FFFFFF)|0x40000000; // top 3 bits
  NVIC_EN0_R = NVIC_EN0_INT19;     // enable interrupt 19 in NVIC
}

void PortB_Init(void)
{
SYSCTL_RCGCGPIO_R |= 0x00000002; // bit1 --> bit0 we are changing portb to porte for lab10

while ( SYSCTL_RCGCGPIO_R ==0){}
GPIO_PORTB_DIR_R = 0x01;
GPIO_PORTB_AFSEL_R = 0x00;
GPIO_PORTB_DEN_R = 0x01;
}
void Timer0A_Handler(void){
//DisableInterrupts();
  TIMER0_ICR_R = TIMER_ICR_TATOCINT;    // acknowledge timer0A timeout
  GPIO_PORTF2 = 0x04;                   // profile
  ADCvalue = ADC0_InSeq3();
  GPIO_PORTF2 = 0x00;
//if (Light == OFF)
//{
if (ADCvalue >= 5000) // trial and error
{
GPIO_PORTB_DATA_R |= 0x01;
//Light = ON;
}
else
{
GPIO_PORTB_DATA_R = 0x00;
}

}
int main(void){
  PLL_Init();                           // 25 MHz
  SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F
  ADC0_InitSWTriggerSeq3(0);            // allow time to finish activating
//  ADC0_InitAllTriggerSeq3(0);           // allow time to finish activating
  Timer0A_Init10HzInt();                // set up Timer0A for 10 Hz interrupts
  GPIO_PORTF_DIR_R |= 0x04;             // make PF2 out (built-in LED)
  GPIO_PORTF_AFSEL_R &= ~0x04;          // disable alt funct on PF2
  GPIO_PORTF_DEN_R |= 0x04;             // enable digital I/O on PF2
                                        // configure PF2 as GPIO
  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000;
  GPIO_PORTF_AMSEL_R = 0;               // disable analog functionality on PF
  GPIO_PORTF2 = 0;                      // turn off LED
  EnableInterrupts();
PortB_Init();
  while(1){
    WaitForInterrupt();
//    GPIO_PORTF2 = 0x04;                 // profile
//    ADCvalue = ADC0_InSeq3();
//    GPIO_PORTF2 = 0x00;
  }
}

Posted by evilmind5 at 12:40 AM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Sunday, April 21, 2019

Keil/Microvision - Creating a New Project for Tiva™ C Series TM4C123G LaunchPad



  1. Create New Folder on Documents (or any location) and name it
  2. On Microvision ==> Project ==> New Microvision Project & name it ==> ARM Cortex M4 ==> ARMCM4
  3. Copy/paste "inc" folder that includes "tm4c123gh6pm.h" on new folder you created on step 1.
  4. Copy/paste "startup.s on new folder your created on step 1.
  5. On Microvision, right-click on Source Group 1
    • Add existing ==> startup.s
    • Add new item to group ==> c file ==> name it "main (or any that you'd like)"
  6. Make sure to click on "options for target" ==> debug ==> "Use:" ==> "Stellaris ICDI"
Posted by evilmind5 at 11:27 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Stepper Motor Code

/*
7 files needed for this code to work:
Header Files
1. stepper.h // don't add to source group
2. systick.h // don't add to source group

Source (group) Code Files (you only add .c type files, not .h which is called on the #include)
3. startup.s // add to source group
4. stepper.c // add to source group
5. main.c (in this case, mainStep.c) // add to source group
6. SysTick.c // add to source group
*/
#include "inc/tm4c123gh6pm.h"
#include <stdint.h>
#include "stepper.h"

#define T1ms 16000 // assumes using 16 MHz PIOSC (default setting // for clock source)

int main(void){

Stepper_Init();

Stepper_CCW(T1ms); // Pos=1; GPIO_PORTD_DATA_R=9
Stepper_CCW(T1ms); // Pos=2; GPIO_PORTD_DATA_R=5
Stepper_CCW(T1ms); // Pos=3; GPIO_PORTD_DATA_R=6
Stepper_CCW(T1ms); // Pos=4; GPIO_PORTD_DATA_R=10
Stepper_CCW(T1ms); // Pos=5; GPIO_PORTD_DATA_R=9
Stepper_CCW(T1ms); // Pos=6; GPIO_PORTD_DATA_R=5
Stepper_CCW(T1ms); // Pos=7; GPIO_PORTD_DATA_R=6
Stepper_CCW(T1ms); // Pos=8; GPIO_PORTD_DATA_R=10

SYSCTL_RCGC2_R |= 0x18; // Using PORT E

GPIO_PORTE_AMSEL_R &=~ 0x01;// 3) disable analog functionality on PD3-0
GPIO_PORTE_DIR_R &=~ 0x01;// 5) make PD3-0 out
GPIO_PORTE_AFSEL_R &=~ 0x01;// 6) disable alt functon PD3-0
GPIO_PORTE_DEN_R |= 0x01;// 7) enable digital I/O on PD3-0

while(1){

if ((GPIO_PORTE_DATA_R &0x01) == 0x00) {
Stepper_CW(2*T1ms); // output every 10ms
}

else {
Stepper_CCW(2*T1ms); // output every 10ms
  //Stepper_Seek(50, 2*T1ms);
}
}

}

https://drive.google.com/drive/u/0/folders/1TmxG8vcH76qDIACuWfLp_aC4nEm4OfSI
Posted by evilmind5 at 11:27 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Friday, March 29, 2019

Advance Traffic Light System

/*
Header: // for #include (see below) and also add file to folder
PLL.h
SysTick.h

Files: // add into Microvision and Folder
PLL.c
SysTick.c
startup.s
*/

#include <stdint.h>
#include "PLL.h"
#include "SysTick.h"

// for volatile... values, go to bottom of the page for explanation
#define LIGHT            (*((volatile unsigned long *)0x400050FC)) // base & 40005000 (PORTB)
#define PLIGHT          (*((volatile unsigned long *)0x4002503C)) // base & 40025000 (PORTF)

#define GPIO_PORTB_OUT          (*((volatile unsigned long *)0x400050FC)) // bits 5-0
#define GPIO_PORTF_OUT          (*((volatile unsigned long *)0x40025028))

#define GPIO_PORTB_DIR_R        (*((volatile unsigned long *)0x40005400))
#define GPIO_PORTB_AFSEL_R      (*((volatile unsigned long *)0x40005420))
#define GPIO_PORTB_DEN_R        (*((volatile unsigned long *)0x4000551C))
#define GPIO_PORTB_AMSEL_R      (*((volatile unsigned long *)0x40005528))
#define GPIO_PORTB_PCTL_R       (*((volatile unsigned long *)0x4000552C))

#define GPIO_PORTE_IN           (*((volatile unsigned long *)0x4002401C)) // bits 2-0
#define SENSOR                  (*((volatile unsigned long *)0x4002401C)) // &PE 4002400
#define GPIO_PORTE_DIR_R        (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL_R      (*((volatile unsigned long *)0x40024420))
#define GPIO_PORTE_DEN_R        (*((volatile unsigned long *)0x4002451C))
#define GPIO_PORTE_AMSEL_R      (*((volatile unsigned long *)0x40024528))
#define GPIO_PORTE_PCTL_R       (*((volatile unsigned long *)0x4002452C))

#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))

#define GPIO_PORTF_DIR_R     (*((volatile unsigned long *)0x40025400)) // additional port, F
#define GPIO_PORTF_AFSEL_R    (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_DEN_R     (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_AMSEL_R    (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R    (*((volatile unsigned long *)0x4002552C))
#define GPIO_PORTF_PUR_R        (*((volatile unsigned long *)0x40025028))

#define SYSCTL_RCGC2_GPIOF    0x00000020  // port F Clock Gating Control
#define SYSCTL_RCGC2_GPIOE      0x00000010  // port E Clock Gating Control
#define SYSCTL_RCGC2_GPIOB      0x00000002  // port B Clock Gating Control


// Linked data structure

struct State {
 unsigned long Out;
 unsigned long Pout;
 unsigned long Time;
 unsigned long Next[8];
};

typedef const struct State STyp;

#define goS      0
#define CautionS   1
#define goW      2
#define CautionW   3
#define PwaitS    4
#define PgoS     5
#define PblinkONS1  6
#define PblinkOFFS1 7
#define PblinkONS2  8
#define PblinkOFFS2 9
#define PwaitW    10
#define PgoW     11
#define PblinkONW1  12
#define PblinkOFFW1 13
#define PblinkONW2  14
#define PblinkOFFW2 15

STyp FSM[16]={ // each line, different states

 {0x21, 0x02, 550,{goS,CautionS,goS,CautionS,PwaitS,PwaitS,PwaitS,PwaitS}},
 {0x22, 0x02, 550,{goW,goW,goW,goW,goW,goW,goW,goW}},
 {0x0C, 0x02, 550,{goW,goW,CautionW,CautionW,PwaitW,PwaitW,PwaitW,PwaitW}},
 {0x14, 0x02, 550,{goS,goS,goS,goS,goS,goS,goS,goS}},
 {0x22, 0x02, 550,{PgoS,PgoS,PgoS,PgoS,PgoS,PgoS,PgoS}},

 {0x24, 0x08, 350,{PblinkONS1,PblinkONS1,PblinkONS1,PblinkONS1,PblinkONS1,PblinkONS1,PblinkONS1,PblinkONS1}},

 {0x24, 0x02, 50,{PblinkOFFS1,PblinkOFFS1,PblinkOFFS1,PblinkOFFS1,PblinkOFFS1,PblinkOFFS1,PblinkOFFS1,PblinkOFFS1}},
 {0x24, 0x00, 50,{PblinkONS2,PblinkONS2,PblinkONS2,PblinkONS2,PblinkONS2,PblinkONS2,PblinkONS2,PblinkONS2}},
 {0x24, 0x02, 50,{PblinkOFFS2,PblinkOFFS2,PblinkOFFS2,PblinkOFFS2,PblinkOFFS2,PblinkOFFS2,PblinkOFFS2,PblinkOFFS2}},

 {0x24, 0x00, 550,{goW,goW,goW,goW,goW,goW,goW,goW}},
 {0x14, 0x02, 550,{PgoW,PgoW,PgoW,PgoW,PgoW,PgoW,PgoW,PgoW}},

 {0x24, 0x08, 350,{PblinkONW1,PblinkONW1,PblinkONW1,PblinkONW1,PblinkONW1,PblinkONW1,PblinkONW1,PblinkONW1}},

 {0x24, 0x02, 50,{PblinkOFFW1,PblinkOFFW1,PblinkOFFW1,PblinkOFFW1,PblinkOFFW1,PblinkOFFW1,PblinkOFFW1,PblinkOFFW1}},
 {0x24, 0x00, 50,{PblinkONW2,PblinkONW2,PblinkONW2,PblinkONW2,PblinkONW2,PblinkONW2,PblinkONW2,PblinkONW2}},
 {0x24, 0x02, 50,{PblinkOFFW2,PblinkOFFW2,PblinkOFFW2,PblinkOFFW2,PblinkOFFW2,PblinkOFFW2,PblinkOFFW2,PblinkOFFW2}},

 {0x24, 0x00, 250,{goS,goS,goS,goS,goS,goS,goS,goS}}};


unsigned long S;  // index to the current state
unsigned long Input;

int main(void){

volatile unsigned long delay;

  PLL_Init();       // 80 MHz, Program 10.1
  SysTick_Init();   // Program 10.2

  SYSCTL_RCGC2_R |= 0x32;      // 1) For Port B, E & F
  delay = SYSCTL_RCGC2_R;      // 2) no need to unlock

 GPIO_PORTE_AMSEL_R &=~ 0x07; // disable analog function on PE1-0
  GPIO_PORTE_AFSEL_R &=~ 0x07; // regular function on PE1-0
  GPIO_PORTE_DIR_R &=~ 0x07;   // inputs on PE1-0
  GPIO_PORTE_DEN_R |= 0x07;    // enable digital on PE1-0
  GPIO_PORTE_PCTL_R &=~ 0x00000FFF; // enable regular GPIO

GPIO_PORTB_AMSEL_R &=~ 0x3F; // disable analog function on PB5-0
  GPIO_PORTB_AFSEL_R &=~ 0x3F; // regular function on PB5-0
  GPIO_PORTB_DIR_R |= 0x3F;    // outputs on PB5-0
  GPIO_PORTB_DEN_R |= 0x3F;    //  enable digital on PB5-0
  GPIO_PORTB_PCTL_R &=~ 0x00FFFFFF; // enable regular GPIO

GPIO_PORTF_AMSEL_R &=~ 0x0A;
  GPIO_PORTF_AFSEL_R &=~ 0x0A;
  GPIO_PORTF_DIR_R |= 0x0A;
  GPIO_PORTF_DEN_R |= 0x0A;
  GPIO_PORTF_PUR_R = 0x0A;
  GPIO_PORTF_PCTL_R &=~ 0x0000F0F0;

  S = goS;

  while(1){
LIGHT = FSM[S].Out;   // set traffic lights
PLIGHT = FSM[S].Pout;  //set Pedestrian lights

    SysTick_Wait10ms(FSM[S].Time);
    Input = SENSOR;       // read sensors

    S = FSM[S].Next[Input];
  }
}


Defining the value for #LIGHT:
(accessing bits 0-5, see left table)
Base: 0x4000 5000
offsets:           0080
                       0040
   +                  0020
                       0010
                       0008
                       0004
_________________
0x 4000 50(8+4+2+1 = 15 => F) (8+4 = 12 => C) == 0x4000 50FC


https://drive.google.com/drive/u/0/folders/1TmxG8vcH76qDIACuWfLp_aC4nEm4OfSI

Posted by evilmind5 at 4:55 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Simple Traffic Light Code For Microvision

/* Required files:

PLL.c // add to software & folder
SysTick.c // add to software & folder
PLL.h // only on folder
SysTick.h // only on folder
startup.s

*/

#include "PLL.h"
#include "SysTick.h"

#define LIGHT                   (*((volatile unsigned long *)0x400050FC))
#define GPIO_PORTB_OUT          (*((volatile unsigned long *)0x400050FC)) // bits 5-0
#define GPIO_PORTB_DIR_R        (*((volatile unsigned long *)0x40005400))
#define GPIO_PORTB_AFSEL_R      (*((volatile unsigned long *)0x40005420))
#define GPIO_PORTB_DEN_R        (*((volatile unsigned long *)0x4000551C))
#define GPIO_PORTB_AMSEL_R      (*((volatile unsigned long *)0x40005528))
#define GPIO_PORTB_PCTL_R       (*((volatile unsigned long *)0x4000552C))

#define GPIO_PORTE_IN           (*((volatile unsigned long *)0x4002400C)) // bits 1-0
#define SENSOR                  (*((volatile unsigned long *)0x4002400C))
#define GPIO_PORTE_DIR_R        (*((volatile unsigned long *)0x40024400))
#define GPIO_PORTE_AFSEL_R      (*((volatile unsigned long *)0x40024420))
#define GPIO_PORTE_DEN_R        (*((volatile unsigned long *)0x4002451C))
#define GPIO_PORTE_AMSEL_R      (*((volatile unsigned long *)0x40024528))
#define GPIO_PORTE_PCTL_R       (*((volatile unsigned long *)0x4002452C))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))

#define SYSCTL_RCGC2_GPIOE      0x00000010  // port E Clock Gating Control
#define SYSCTL_RCGC2_GPIOB      0x00000002  // port B Clock Gating Control


// Linked data structure
struct State {
  unsigned long Out;
  unsigned long Time;
  unsigned long Next[4];
};

typedef const struct State STyp;
#define goN   0
#define waitN 1
#define goE   2
#define waitE 3

STyp FSM[4] = {
 {0x21,500,{goN,waitN,goN,waitN}},
 {0x22, 200,{goE,goE,goE,goE}},
 {0x0C,500,{goE,goE,waitE,waitE}},
 {0x14, 200,{goN,goN,goN,goN}}
};

unsigned long S;  // index to the current state
unsigned long Input;
int main(void){
volatile unsigned long delay;
  PLL_Init();       // 80 MHz, Program 10.1
  SysTick_Init();   // Program 10.2

  SYSCTL_RCGC2_R |= 0x12;      // 1) B E
  delay = SYSCTL_RCGC2_R;      // 2) no need to unlock

  GPIO_PORTE_AMSEL_R &= ~0x03; // 3) disable analog function on PE1-0
  GPIO_PORTE_AFSEL_R &= ~0x03; // 6) regular function on PE1-0
  GPIO_PORTE_DIR_R &=~ 0x03;   // 5) inputs on PE1-0
  GPIO_PORTE_DEN_R |= 0x03;    // 7) enable digital on PE1-0
  GPIO_PORTE_PCTL_R &=~ 0x000000FF; // 4) enable regular GPIO

  GPIO_PORTB_AMSEL_R &= ~0x3F; // 3) disable analog function on PB5-0
  GPIO_PORTB_PCTL_R &= ~0x00FFFFFF; // 4) enable regular GPIO
  GPIO_PORTB_DIR_R |= 0x3F;    // 5) outputs on PB5-0
  GPIO_PORTB_AFSEL_R &= ~0x3F; // 6) regular function on PB5-0
  GPIO_PORTB_DEN_R |= 0x3F;    // 7) enable digital on PB5-0
  S = goN;
  while(1){

    LIGHT = FSM[S].Out;  // set lights
    SysTick_Wait10ms(FSM[S].Time);
    Input = SENSOR;     // read sensors
    S = FSM[S].Next[Input];
  }
}


Use 1k Resistors


Posted by evilmind5 at 1:40 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: kiel, microvision, traffic light

Thursday, March 28, 2019

7-Segment Display Code using Kiel/Microvision

https://outreach.phas.ubc.ca/2015/06/05/an-introduction-to-seven-segment-displays/

Materials:
  • 1x   7-segment display ✓
  • 15+ wires ✓
  • 10+ 500 or 1k resistors ✓
  • 1x   breadboard ✓
  • 1x   TI board ✓
  • 1x   power supply + power supply adapter (Optional but recommended to use it in this lab. They come with the Arduino kit.)
Before wiring and writing program, you are required to research on following topics:
1. Find out different types of 7-segment displays.
2. Based on the type of your own 7-segment display, figure out how to wire it correctly.
You need to build skills on researching and learning unknown knowledge independently and efficiently. This benefits you for long term such as when you take senior design, work in company, or invent your own products, etc. Try your best to get as little help from instructor as possible. When you struggle but try very hard to solve the problem, and once you solve it, you can remember it. That's the best way to improve building and problem solving skills. If you spent lots of time (5+ hours) and still struggling, and then it's the time to ask for help.
Step 1: Research and find out the different types of 7-segment displays.
Question 1: How many types of 7-segment displays?
Question 2: What are the names of these types.
Question 3: What are their differences?

Caution: Different types of 7-segment displays require different ways to wire.

Step 2: Wire all necessary pins. Make sure to connect a 500 - 1k resistor to each LED to prevent LED from burning.

In this lab, build a down counter system that meets following design specifications & requirements:

Specifications:
  • System operates by a 3.3V source.
  • System has one ARM chip.
  • Design has 1 7-segment display.

Requirements:
  • While system is running, counter counts up.
  • When system turns on, counter begins counting from 0.
  • System's counts 0, 1, ... to 9 and then repeats.

Using SysTick Code on Keil/Micro-vision


// LAB 5 - 7Display Counter
#include "inc/tm4c123gh6pm.h"

//void delay(); //Activating delay function

void PLL_Init(void){
// 0) Use RCC2
SYSCTL_RCC2_R |= 0x80000000; // USERCC2 // 1) bypass PLL while initializing
SYSCTL_RCC2_R |= 0x00000800; // BYPASS2, PLL bypass // 2) select the crystal value and oscillator source
SYSCTL_RCC_R = (SYSCTL_RCC_R &~0x000007C0) // clear XTAL field, bits 10-6
+ 0x00000540; // 10101, configure for 16 MHz crystal
SYSCTL_RCC2_R &= ~0x00000070; // configure for main oscillator source // 3) activate PLL by clearing PWRDN
SYSCTL_RCC2_R &= ~0x00002000; // 4) set the desired system divider
SYSCTL_RCC2_R |= 0x40000000; // use 400 MHz PLL
SYSCTL_RCC2_R = (SYSCTL_RCC2_R&~ 0x1FC00000) // clear system clock divider
+ (4<<22); // configure for 80 MHz clock // 5) wait for the PLL to lock by polling PLLLRIS

while((SYSCTL_RIS_R&0x00000040) == 0){}; // wait for PLLRIS bit

SYSCTL_RCC2_R &= ~0x00000800; // 6) enable use of PLL by clearing BYPASS
}

void SysTick_Init(void){

NVIC_ST_CTRL_R = 0;               // disable SysTick during setup
NVIC_ST_CTRL_R = 0x00000005;      // enable SysTick with core clock

}
// The delay parameter is in units of the 80 MHz core clock. (12.5 ns)
void SysTick_Wait(unsigned long delay){

NVIC_ST_RELOAD_R = delay-1;  // number of counts to wait
NVIC_ST_CURRENT_R = 0;       // any value written to CURRENT clears
while((NVIC_ST_CTRL_R&0x00010000) == 0){}

}
// 800000*12.5ns equals 10ms
void SysTick_Wait10ms(unsigned long delay){

unsigned long i;

for (i = 0; i < delay; i++){
SysTick_Wait(800000);  // wait 10ms
}
}

int main(){

SysTick_Init();
PLL_Init();

SYSCTL_RCGC2_R = 0x02; // Using PORT B

GPIO_PORTB_DIR_R |= 0xFF;  // ACTIVATE ALL PINS PB0 - PB7
GPIO_PORTB_DEN_R |= 0xFF; // DIGITAL ENABLE
GPIO_PORTB_AMSEL_R &=~ 0xFF; // DEACTIVATE ANALOG FEATURES
GPIO_PORTB_AFSEL_R &=~ 0xFF; // DEACTIVATE ALTERNATIVE FUNCTION

while(1){

//GPIO_PORTB_DATA_R &=~ 0XFE; // LED all clears
GPIO_PORTB_DATA_R = 0XEE; // Number 0 (7-segment display)
SysTick_Wait10ms(100); // added for delay for each segment

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0X82; // Number 1
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0XDC; // Number 2
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0XD6; // Number 3
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R |= 0XB2; // Number 4
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0X76; // Number 5
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0X7E; // Number 6
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0XC2; // Number 7
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0XFE; // Number 8
SysTick_Wait10ms(100);

//GPIO_PORTB_DATA_R &=~ 0XFE;
GPIO_PORTB_DATA_R = 0XF2; // Number 9
SysTick_Wait10ms(100);
}

return 0;

}


Posted by evilmind5 at 2:47 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: 7 segment display, kiel, microvision
Older Posts Home
Subscribe to: Posts (Atom)

About Me

My photo
evilmind5
View my complete profile

Blog Archive

  • ▼  2022 (2)
    • ▼  Jan (2)
      • Sw1 Press [On] Red LED (w/ Video)
      • Blinking Red LED (w/ Video)
  • ►  2019 (6)
    • ►  Jun (1)
    • ►  Apr (2)
    • ►  Mar (3)
  • ►  2018 (4)
    • ►  Jun (2)
    • ►  Jan (2)
  • ►  2017 (16)
    • ►  Dec (14)
    • ►  Aug (1)
    • ►  Jul (1)
Picture Window theme. Powered by Blogger.