viernes, 23 de febrero de 2018



PORTB & Seven Segment Display




Thus the PORTB.0 is going to be a
PORTB.1 is the b terminal and so on.



Display
a
b
c
d
e
f
g
0
1
1
1
1
1
1
0
1
0
1
1
0
0
0
0
2
1
1
0
1
1
0
1
3
1
1
1
1
0
0
1
4
0
1
1
0
0
1
1
5
1
0
1
1
0
1
1
6
1
0
1
1
1
1
1
7
1
1
1
0
0
0
0
8
1
1
1
1
1
1
1
9
1
1
1
1
0
1
1
--------------------------------------------------------------------------------------------------------------------------


#include "TM4C123.h"                    // Device header

// begins the definition of the registers of Port B to be used as a GPIO
#define SYSCTL_RCGC2_R     (*((volatile unsigned long *)0x400FE108))
#define GPIO_PORTB_PCTL_R  (*((volatile unsigned long *)0x4000552C))
#define GPIO_PORTB_AMSEL_R (*((volatile unsigned long *)0x40005528))
#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_DATA_R  (*((volatile unsigned long *)0x400053FC))
// ends the definition of the registers of Port B

// begins the definition of the registers of Port F to be used as a GPIO
#define GPIO_PORTF_DATA_R       (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R        (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R      (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_PUR_R        (*((volatile unsigned long *)0x40025510))
#define GPIO_PORTF_DEN_R        (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_LOCK_R       (*((volatile unsigned long *)0x40025520))
#define GPIO_PORTF_CR_R         (*((volatile unsigned long *)0x40025524))
#define GPIO_PORTF_AMSEL_R      (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R       (*((volatile unsigned long *)0x4002552C))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))
// ends the definition of the registers of Port F


int i=0;

void PortB_Init(void);
void delay(unsigned long halfsecs);

int main()
{
char x [] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};

PortB_Init();

while(1)
{

for(i = 0; i < 10; i++)
{
GPIO_PORTB_DATA_R |= x[i];
delay(5);
GPIO_PORTB_DATA_R &= 0x00;
}

}
}


void PortB_Init(void){
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000002; //1) activate clock for Port B
delay = SYSCTL_RCGC2_R; //allow time for clock to start
GPIO_PORTB_AMSEL_R &= ~0xFF; // 3) disable analog on PA5
GPIO_PORTB_PCTL_R &= ~0xFFFFFFFF; // 4) PCTL GPIO on PA5
GPIO_PORTB_DIR_R |= 0xFF; // 5) direction PortB output
GPIO_PORTB_AFSEL_R &= ~0xFF; // 6) PB regular port function
GPIO_PORTB_DEN_R |= 0xFF; // 7) enable the PB as a digital port
}

void delay(unsigned long halfsecs){
  unsigned long count;

  while(halfsecs > 0 ) { // repeat while there are still halfsecs to delay
    count = 1538460; // 400000*0.5/0.13 that it takes 0.13 sec to count down to zero
    while (count > 0) {
      count--;
    } // This while loop takes approximately 3 cycles
    halfsecs--;
  }
}
















No hay comentarios.:

Publicar un comentario

BTFSS INSTRUCTION  IN ASSEMBLER FOR PIC18F In this sample, we show that how to use a switch input to make an action. Remember that I...