標(biāo)題:
AT90S8515單片機SPI驅(qū)動74LS595源程序
[打印本頁]
作者:
新洲羅遠(yuǎn)
時間:
2020-3-31 07:17
標(biāo)題:
AT90S8515單片機SPI驅(qū)動74LS595源程序
AT90S8515使用SPI驅(qū)動74LS595。
我這里使用了SS口線PB.4,作為74LS595的鎖存信號,關(guān)鍵是把PB.4設(shè)置為輸出。
74LS595驅(qū)動發(fā)光管顯示加1計數(shù),我用SPI最高速度,所以顯示16位計數(shù)高八位,低八位太快,看不清楚。
5d6034a85edf8db1b0806a680923dd54564e740b.jpg
(75.04 KB, 下載次數(shù): 79)
下載附件
2020-3-31 07:13 上傳
單片機源程序如下:
//ICC-AVR application builder : 2020/3/30 22:23:31
// Target : 8515
// Crystal: 8.0000Mhz
#include <io8515v.h>
#include <macros.h>
#define SS_ON PORTB |= BIT(4); //E置1
#define SS_OFF PORTB &= ~BIT(4); //E置0
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
DDRB = 0xff;
PORTB = 0xFF; //復(fù)用SS腳的關(guān)鍵是PB.4設(shè)為輸出
PORTC = 0x00;
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0xFF;
}
//SPI initialize
// clock rate: 62500hz
void spi_init(void)
{
SPCR = 0xFC; //setup SPI
}
int spi_d =0X00; //太快,用高8位
#pragma interrupt_handler spi_stc_isr:iv_SPI_STC
void spi_stc_isr(void)
{
//byte in SPDR has been sent/received
SS_OFF; //PB.4=0
SS_ON; //PB.4=1
spi_d = spi_d+1;
SPDR = spi_d>>8;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
spi_init();
MCUCR = 0x00;
GIMSK = 0x00;
TIMSK = 0x00;
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices(); //初始化系統(tǒng)
SPDR=0X00;
while(1)
{}
}
復(fù)制代碼
以上程序51hei提供下載:
SPI01.zip
(9 KB, 下載次數(shù): 8)
2020-3-31 07:16 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1