CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SPI missing chars? 4x4 Keypad -> 16F88 -> 16F877

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kd5uzz



Joined: 28 May 2006
Posts: 56

View user's profile Send private message

SPI missing chars? 4x4 Keypad -> 16F88 -> 16F877
PostPosted: Sat Apr 21, 2007 10:32 am     Reply with quote

I'm still working on my Keypad -> SPI encoder using an F88. Using the code below,if I enable RS232 output on the F88 I see every keypress, but the master only sees about 20 - 30% (even when RS232 output is disabled). When the master starts an SPI transaction it sends NULL as the data, if it receives the same value back then we know the slave didn't service the SPI transaction, i.e. there is no new keypress. Should I have pullup resistors on the SPI data lines?
Compiler 3.222
SPI Slave code:
Code:

#include <16F88.H>
#fuses INTRC_IO
#fuses NOWDT, BROWNOUT, NOLVP
#use delay(clock=500000)

#use rs232(baud=2400,xmit=PIN_B3,rcv=PIN_B3,ERRORS)

#include <flex_keypad_4x4.c>
//******************************
// Functions
//******************************
//******************************
// Global Defs
//******************************

//******************************
// Code
//******************************

void main(){
   char k,spidata;
   int BP = 0;

   output_high(PIN_B7);
   delay_ms(100);
   output_low(PIN_B7);
   delay_ms(100);
   output_high(PIN_B7);
   delay_ms(100);
   output_low(PIN_B7);

   kbd_init();

   setup_spi(spi_slave | spi_l_to_h);
   delay_ms(5);
   printf("\n\r4x4 Keypad to SPI Converter");

   while(TRUE){
      k=kbd_getc();
      if(k!=0){
         output_high(PIN_B7);
         //printf("Key: %i = '%c'\n\r sent to SPI...",k,k);
         spidata = spi_read(k);
         output_low(PIN_B7);
      }
   }
}



SPI Master code:
Code:

#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)             //clock speed
#use rs232(baud=2400,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#include "flex_lcd420.c"
#include <string.h>
//******************************
// Functions
//******************************
void SecondPassed();
int kbd_getc();
int waitforkbd();
void startup();
//******************************
// Global Defs
//******************************
#define LCD_BACKLIGHT_ON  output_high(PIN_A0)
#define LCD_BACKLIGHT_OFF output_low(PIN_A0)

#define LED2_RED        output_high(PIN_D6)
#define LED2_RED_OFF    output_low(PIN_D6)
#define LED2_GREEN      output_high(PIN_D7)
#define LED2_GREEN_OFF  output_low(PIN_D7)

#define LED1_RED        output_high(PIN_B3)
#define LED1_RED_OFF    output_low(PIN_B3)
#define LED1_GREEN      output_high(PIN_B4)
#define LED1_GREEN_OFF  output_low(PIN_B4)

#define KEYPAD_ENABLE   output_low(PIN_D4)
#define KEYPAD_DISABLE  output_high(PIN_D4)

int BlinkState,SecondCount;
int LCDContrast = 24;
//******************************
// Code
//******************************
void Main(){
   int i;
   delay_ms(5);

   startup();

   while(TRUE){

      KEYPAD_ENABLE;
      i = spi_read(0);
      KEYPAD_DISABLE;
      if (i != 0){
         printf("Key:%c ASCII: %d\n\r",i,i);
      }
   }
}

void startup(){
   enable_interrupts(INT_TIMER2); //used to drive LED display
   setup_timer_2(T2_DIV_BY_1, 130, 1);
   setup_ccp1(CCP_PWM);

   setup_spi(spi_master |spi_l_to_h | spi_clk_div_16 );
   KEYPAD_DISABLE;

   enable_interrupts(GLOBAL);   //Actually enable them

   //lcd_init();

   //set_pwm1_duty(LCDContrast);
   //LCD_BACKLIGHT_ON;
   printf("\fKAB 1.0\nHardware Test 1.0\nSystem Online\nPlease Wait...");
   delay_ms(2000);
   //LCD_BACKLIGHT_OFF;
}
kd5uzz



Joined: 28 May 2006
Posts: 56

View user's profile Send private message

PostPosted: Sat Apr 21, 2007 6:09 pm     Reply with quote

Code:

     k++;

      if (k>25){
         k=0;
      }
      spidata = spi_read(k+65);



Sends A-Z, as fast as the master can poll the slave, perfectly everytime.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group