找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2850|回復: 0
收起左側

AT90S8515單片機SPI驅(qū)動74LS595源程序

[復制鏈接]
ID:716413 發(fā)表于 2020-3-31 07:17 | 顯示全部樓層 |閱讀模式
AT90S8515使用SPI驅(qū)動74LS595。
我這里使用了SS口線PB.4,作為74LS595的鎖存信號,關鍵是把PB.4設置為輸出。
74LS595驅(qū)動發(fā)光管顯示加1計數(shù),我用SPI最高速度,所以顯示16位計數(shù)高八位,低八位太快,看不清楚。

5d6034a85edf8db1b0806a680923dd54564e740b.jpg

單片機源程序如下:
  1. //ICC-AVR application builder : 2020/3/30 22:23:31
  2. // Target : 8515
  3. // Crystal: 8.0000Mhz

  4. #include <io8515v.h>
  5. #include <macros.h>

  6. #define SS_ON PORTB |= BIT(4);     //E置1
  7. #define SS_OFF PORTB &= ~BIT(4);   //E置0

  8. void port_init(void)
  9. {
  10. PORTA = 0x00;
  11. DDRA  = 0x00;
  12. DDRB  = 0xff;
  13. PORTB = 0xFF; //復用SS腳的關鍵是PB.4設為輸出
  14. PORTC = 0x00;
  15. DDRC  = 0x00;
  16. PORTD = 0x00;
  17. DDRD  = 0xFF;
  18. }

  19. //SPI initialize
  20. // clock rate: 62500hz
  21. void spi_init(void)
  22. {
  23. SPCR = 0xFC; //setup SPI
  24. }

  25. int spi_d =0X00;          //太快,用高8位

  26. #pragma interrupt_handler spi_stc_isr:iv_SPI_STC
  27. void spi_stc_isr(void)
  28. {
  29.               //byte in SPDR has been sent/received
  30.      SS_OFF;   //PB.4=0
  31.          SS_ON;    //PB.4=1
  32.      spi_d = spi_d+1;
  33.          SPDR = spi_d>>8;
  34. }

  35. //call this routine to initialize all peripherals
  36. void init_devices(void)
  37. {
  38. //stop errant interrupts until set up
  39. CLI(); //disable all interrupts
  40. port_init();
  41. spi_init();

  42. MCUCR = 0x00;
  43. GIMSK = 0x00;
  44. TIMSK = 0x00;
  45. SEI(); //re-enable interrupts
  46. //all peripherals are now initialized
  47. }

  48. void main(void)
  49. {
  50.     init_devices();         //初始化系統(tǒng)
  51.    
  52. SPDR=0X00;
  53. while(1)
  54.     {}
  55. }
復制代碼

以上程序51hei提供下載:
SPI01.zip (9 KB, 下載次數(shù): 8)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表