ARM7 Getting Started 12, SPI Communication

Publisher:ziyuntingLatest update time:2016-11-01 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The digital tube displays 1-F.

Main program:

/*******************************************************************************
*File: Main.c
*Function: The LED digital tube displays characters 0-F, and controls 4 LEDs to display the corresponding hexadecimal
******************************************************************************/
#include "config.h"
#define HC595_CS 0x00000100 /*P0.8 port is the chip select of 74HC595*/
uint8 rcv_data;
/***********************************************************************************
*Name: DelayNS()
*Function: Long software delay
******************************************************************************/
void DelayNS(uint32 dly)
{ uint32 i;
   for (;dly>0;dly--)
      for(i=0;i<50000;i++);
}
/*******************************************************************************
*Name: MSpiIni()
*Function: Initialize SPI interface and set it as host
****************************************************************************/
void MSpiIni(void)
{ S0PCCR=0x52; //Set SPI clock division
  S0PCR=0x30; //Set SPI interface mode, MSTR=1, CPOL=1, CPHA=0, LSBF=0
}
/***********************************************************************************
*Name: MSendData()
*Function: Send data to SPI bus
***************************************************************************/
uint8 MSendData(uint8 data)
{ IO0CLR=HC595_CS; //Chip select
  S0PDR=data;
  while(0==(S0PSR&0x80)); //Wait for SPIF to be set, that is, wait for data to be sent
  IO0SET=HC595_CS;
  return(S0PDR);
}
/*This table is the font of 0~F*/
  uint8 const DISP_TAB[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
                            0x88,0x83,0xC6,0xA1,0x86,0x8E};
/*******************************************************************************
*Name: main()
*Function: Use the hardware SPI interface to output data from 0~F and control the LED display
*******************************************************************************/

int main(void)

  uint8 i;  
  
  PINSEL0=0x00005500; //Set SPI pin connection
  PINSEL1=0x00000000;
  
  IO0DIR=HC595_CS; 
  MSpiIni(); //Initialize SPI interfacewhile
  (1)
  { for (i=0;i<16;i++) 
    {rcv_data=MSendData(DISP_TAB[i]); //Send display data
      DelayNS(50); //Delay
    }
  }
  
}

Reference address:ARM7 Getting Started 12, SPI Communication

Previous article:ARM7 Getting Started 12, SPI Communication
Next article:ARM7 Getting Started 13, Timer Control LED Flashing

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号