![]() |
|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#1 |
Đệ tử 4 túi
Tham gia ngày: Oct 2007
Bài gửi: 79
: |
Nhờ giúp đỡ về giao tiếp SPI
Chào các bác, e vừa mua 1con module LED7, mà ác cái nó xài MAX7219 để điều khiển, con này lại dùng giao tiếp SPI, e chưa thử bao giờ, vật lộn với nó cả ngày chẳng xong nên nhờ các bác giúp đỡ, code e test như sau:
Code:
#include <16F877A.H> #include <def_877a.h> #device *=16 ADC=8 #FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT #use delay(clock=20000000) #use fast_io(b) #use fast_io(c) #use fast_io(d) #include <DS1820.c> #include <Temperature.c> #define Chip_Select PIN_C0 //RC0 Chip select // Here we set the configuration of max7219. void max7219_init1() { output_low(Chip_Select); // SELECT MAX SPI_write(0x09); // BCD mode for digit decoding SPI_write(0x00); output_high(Chip_Select); // DESELECT MAX output_low(Chip_Select); // SELECT MAX SPI_write(0x0A); SPI_write(0x0F); // Segment luminosity intensity output_high(Chip_Select); // DESELECT MAX output_low(Chip_Select); // SELECT MAX SPI_write(0x0B); SPI_write(0x07); // Display refresh output_high(Chip_Select); // DESELECT MAX output_low(Chip_Select); // SELECT MAX SPI_write(0x0C); SPI_write(0x01); // Turn on the display output_high(Chip_Select); // DESELECT MAX output_low(Chip_Select); // SELECT MAX SPI_write(0x00); SPI_write(0xFF); // No test output_high(Chip_Select); // DESELECT MAX } void main() { SET_TRIS_C(0x00); setup_spi(spi_master|spi_l_to_h|spi_clk_div_16); Delay_ms(1000); max7219_init1(); // initialize max7219. Delay_ms(1000); do // infinite loop. { output_low(Chip_Select); // select max7219. SPI_write(0x02); // send digit place. Delay_us(10); SPI_write(0x01); // send value to max7219. output_high(Chip_Select); } while(1); // do forever. }
__________________
Dao nao cung la dao, dao cao dai cung la dao. |
![]() |
![]() |
Ðiều Chỉnh | |
Xếp Bài | |
|
|