English 中文(简体)
mikroC中两个微控制器之间的spi接口
原标题:spi interfacing between two microcontroller in mikroC
  • 时间:2012-05-27 17:03:22
  •  标签:
  • mikroc

我正在mikroC中的两个pic18F452微控制器之间进行spi接口,但我的程序没有给出任何输出。我从主站发送数据,从站必须在LCD上显示。

这是我的主从代码:

主代码:

    unsigned char key= a ;

    void main(void)
    {

    TRISC.F2=0; //output for Slave select

    TRISC.F3=0; //SCK output

    TRISC.F4=1; //SDI input

    TRISC.F5=0; //SDO output

    Spi_Init_Advanced(Master_OSC_div64, Data_SAMPLE_MIDDLE, CLK_Idle_HIGH, HIGH_2_LOW);

    SSPCON1.SSPEN=1; //Synchronus serial port enable

    SSPSTAT.SMP=0;  //sampled at middle of data output time


    while(1)

   {

   PORTC.F2=0;

   SSPBUF=key;

   while(!SSPSTAT.bf);

   spi_write(key);

   }

   }

终止

从属代码:

   #define LCD PORTB

   unsigned char key;

   void main(void)

   {

   TRISB=0; //LCD output

   TRISC.F4=1; //SDI input

   TRISC.F3=1; //SCK input from master

   TRISC.F5=0; //SDO output

   TRISA.F5=1; //Slave select input from master 

   SSPSTAT.SMP=0; //input data sampled at middle

   SSPSTAT.CKE=0; // transition from idle to active

   SSPCON1.=0x22;

   Spi_Init_Advanced(SLAVE_SS_ENABLE, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);

   Lcd_init(&PORTB);

   Lcd_cmd(Lcd_clear);

   Lcd_cmd(Lcd_cursor_off);

   while(1)
   {
   if(SSPSTAT.BF)
         {
            key=spi_read(SSPBUF);

            }

   }
   }

/终止/

问题回答

我对这部分不太确定

Lcd_init(&;PORTB)

Lcd_cmd(Lcd_clear);

Lcd_cmd(Lcd_cursor_off);

试着这样声明你的lcd端口。我使用端口d

 //lcd
sbit LCD_RS at RD0_bit;
sbit LCD_RW at RD1_bit;
sbit LCD_EN at RD2_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;
// Pin direction
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_RW_Direction at TRISD1_bit;
sbit LCD_EN_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD4_bit;

以及启动和清除

LCD_Init(); // Initialize LCD
DELAY_MS(100);
Lcd_Cmd(_LCD_CLEAR);                      // Clear display

延迟部分有时可能会派上用场。





相关问题
如何使用 c 和 pic16f84a 优化此代码?

我用 MIKROC 程序 pic16f84a, 并有以下功能 挥发性, 未签名短 d; / / 全球可变空白 put_ data () { RA3_bit = d & 1; d = 1; RA4_bit = d &...

PIC18f452 港口聆听问题

为什么这一法典发挥作用? 我所希望的是,当我发布一个顿的话,那是 port。

Convert if statements to for loop? [closed]

I ve written a function in mikroC that scan the pressed key in a 4x4 keypad void scan_key() { PORTB = 0B11111110; if ( PORTB == 0b11101110){ Row = 1; Column = 1; ...

pic18f communicating with lcd module

I m developing on a pic 18Fxxx (18F452) in assembly. I m in a learning phase so I m doing different simple exercise with the final goal to develop a "real" project. At the moment I m stuck with the ...

How to use Internal Clock of PIC

How to use the PIC micro controller s internal clock without using an external crystal? Why most people prefer external crystals? Better if somebody can give a comparison Thanks

热门标签