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;
}
No comments:
Post a Comment