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 CCS Technical Support

Pic16f690 not sending bytes
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah
Guest







PostPosted: Fri Jul 18, 2008 5:27 am     Reply with quote

The PS/2 interface, sends 'key data', rather than 'keyboard characters'. You get a 'make' code, then normally '0xF0', and then a 'release' code. These codes are sent at between 100000bps, and 16000bps.

A typical typist, will only send a few tens of characters per second _on average_. So 1200bps, is a 'lovely' rate, to send the data being typed _after it has been decoded_, or buffered. However it is not a suitable rate to send the PS/2 data 'unbuffered' as you are doing.

The problem is, what happens if (for instance), the person types 'shift A', then releases these keys. On the down stroke, the two scan codes can arrive right after one another. On the 'release', you get 0xF0, followed by the first code, then another 0xF0, and the second code, so you could potentially have the keyboard wanting to deliver four codes ASAP. At this point, you disappear off potentially to send the first code. The first one (using the hardware UART), is basically instantaneous - just transfers into the output buffer. However after the second, the transmit code has to wait for the last character to send, before the next can be sent. At this point, you will miss the next character from the keyboard...

Hence,you need to be sending the data using an interrupt driven 'buffered' transmission, so the main code can keep scanning the port, to avoid missing anything, _or_ force the PS/2 clock line 'low', which tells the keyboard to 'hold' the next byte (PS/2 'keyboard inhibit'). Otherwise you _will_lose data.

Best Wishes
Guest








PostPosted: Sat Jul 19, 2008 7:27 am     Reply with quote

Thank you very much for clarifying that for me.

Razz
Blasterdito



Joined: 19 Jul 2008
Posts: 5

View user's profile Send private message

Pic16f690 not sending bytes
PostPosted: Mon Aug 04, 2008 2:50 pm     Reply with quote

PCM programmer wrote:
Make a test program. Prove that your PIC can talk to the PC via RS-232.


I have tryed it with your code, I also tryed it with setting all pins digital
like this

Code:

#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, MCLR
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5, ERRORS)

//=============================
void main()
{
SETUP_ADC_PORTS(0); //sets all pins digital,

printf("Hello world");

while(1);
}


I'm trying to use software uart and using pin_A4 to send.
I have conected pin_A4 to a usb module (RXD pin, Receive Asynchronous Data Input).
http://www.dlpdesign.com/um232r-v101.pdf
since it's true TTL a MAX232 chip is not nessecary.

I have also tested to run led software provided with pickit2 cd just to test that pic is working.

I get nothing in terminal?
the terminial software I'm using (realterm) is set to no parity, 1 stop bit, ascii and 9600 baud.



regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 04, 2008 3:15 pm     Reply with quote

Post your compiler version.
Ttelmah
Guest







PostPosted: Mon Aug 04, 2008 3:25 pm     Reply with quote

How have you got the VCCIO pin connected (pin 4)?. How is J2 jumpered?. How is J1 jumpered?. What is your supply voltage?.

Best Wishes
Blasterdito



Joined: 19 Jul 2008
Posts: 5

View user's profile Send private message

PostPosted: Mon Aug 04, 2008 3:27 pm     Reply with quote

thnx for a fast reply

I'm using CCS 4.075, PCM
Blasterdito



Joined: 19 Jul 2008
Posts: 5

View user's profile Send private message

PostPosted: Mon Aug 04, 2008 3:35 pm     Reply with quote

Ttelmah wrote:


Hi

The voltage is 5 volt and supplyed by the pickit programer (also MCLR is checked )

Quote:
How have you got the VCCIO pin connected (pin 4)?. How is J2 jumpered?. How is J1 jumpered?.


That I don't know what it is, I will check this out in data sheet
Blasterdito



Joined: 19 Jul 2008
Posts: 5

View user's profile Send private message

PostPosted: Mon Aug 04, 2008 4:05 pm     Reply with quote

Ttelmah wrote:
How have you got the VCCIO pin connected (pin 4)?.


On pics pin 4, MCLR is enabled if that is what you mean?

The pic it self is powered by pickit2 programmer.


cheers
Blasterdito



Joined: 19 Jul 2008
Posts: 5

View user's profile Send private message

Hyperterminal receiving garbage?
PostPosted: Thu Aug 28, 2008 11:49 am     Reply with quote

Hi everybody.

Áfter some more sleepless nights and a minor psychological meltdown, I have finally got some things to work, but I have this problem.

Instead of receiving plain bytes, I'm getting a lot of garbage in Hyperterminal window when pressing keyboard.

I'm using hardware UART and interrupts,
here is the code. Any help very appreciated.

Code:

 
#include <16F690.h>
#fuses INTRC_IO,NOWDT,NOPROTECT, MCLR
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5)

//-----------------------------------//
//PIN CONFIGURATION

#define PS2_DATA   PIN_A1   

//----- LED -------------------------//
#define HB_LED            PIN_B4
#define HB_LED_TOGGLE()      output_toggle(HB_LED)
#define HB_LED_ON()         output_high(HB_LED)
#define HB_LED_OFF()      output_low(HB_LED)

//----- BUZZER ----------------------//
#define KBD_LED            PIN_A5
#define KBD_LED_ON()      output_high(KBD_LED)
#define KBD_LED_OFF()      output_low(KBD_LED)
#define KBD_LED_TOGGLE()   output_toggle(KBD_LED)

unsigned char   tickCounter;
//PS@
unsigned char PS2Key_bit_Ix=0;   //bit index of the byte stream, Start_bit(1), Parity(10), Stop_bit(11)
unsigned char PS2Key_Code;      //Key code from PS/2 keyboard
unsigned char PS2Key_value;
unsigned char PS2_key_ready=0;
unsigned char PS2_key_timeout=0;

#INT_RDA
void serial_isr()
{
   int8 t;
   t = fgetc();
   //putc(t);
}
#INT_EXT
void int_isr()
{
   PS2Key_bit_Ix++;
   if (PS2Key_bit_Ix==1)
   {
      if ( input_state(PS2_DATA) == 1 )
      {
         PS2Key_bit_Ix=0;
         PS2_key_timeout = 0;
      }      
      PS2Key_Code=0;            
   }
   else if (PS2Key_bit_Ix==10)//  Parity bit,
   {   
      //nothing do here
   }
   else if (PS2Key_bit_Ix==11)   // Stop bit
   {   
      if (input_state(PS2_DATA) == 1)
      {   
         PS2Key_value=PS2Key_Code;
         PS2_key_ready=1;
      }
      PS2Key_bit_Ix=0;
      PS2_key_timeout = 0;
   }
   else// For all bits from 2, 3...9 (total 8-bit)
   {   
      PS2Key_Code >>= 1;
       if (input_state(PS2_DATA)==1) PS2Key_Code |= 0x80;
   }

   clear_interrupt(INT_EXT);
}
// This interrupt is used to output LED toggle
#INT_TIMER2
void timer2_isr() {

   tickCounter++;
   if(++tickCounter == 250){ //~.5 second
      tickCounter=0;
      HB_LED_TOGGLE();
   }
   //clear_interrupt(INT_TIMER2);
}

void init()
{
    //setup_comparator(NC_NC_NC_NC);

   setup_oscillator(OSC_8MHZ);//

      disable_interrupts(GLOBAL);//disable global

   setup_adc_ports( NO_ANALOGS );
   
   SET_TRIS_A( 0x0F ); //A0,A1(PS2-DATA),A2(PS2-CLOCK),A3 - input; A4,A5(KBD_LED) - output
   SET_TRIS_B( 0x20 ); //B4(HB_LED),B7(TX) - output; B5(RX) - input
   SET_TRIS_C( 0x00 ); //C0-C7 - input
   
   enable_interrupts(INT_RDA);//enable uart rcieve interrupt

   KBD_LED_OFF();   
   HB_LED_OFF();

   port_b_pullups(TRUE); //enable pullup

   ext_int_edge( H_TO_L );   // Sets up EXT
   enable_interrupts(INT_EXT);//enable exernal interrupt

   setup_timer_2(T2_DIV_BY_16,0xC0,5);   // setup interrupts

      enable_interrupts(INT_TIMER2);

   enable_interrupts(GLOBAL);//enable global interrupts

}
void test()
{
   printf("testing");
   while(1)
   {
      if(PS2_key_ready == 1)
      {
         KBD_LED_TOGGLE();
         printf("%c",PS2Key_value);
         PS2_key_ready = 0;
      }
   }

}
void main()
{
   init(); //hwardware initialization

   test(); //for testing

   while(1); //never execute this statement.

}




Regards Rolling Eyes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 12:32 pm     Reply with quote

Change it to printf Hex bytes (and put a space after it):
Code:
printf("%x ", PS2Key_value);

Then look at the hex value and compare it to a chart of keyboard
scancodes. This page has got several charts:
http://www.barcodeman.com/altek/mule/scandoc.php
Guest








PostPosted: Thu Aug 28, 2008 3:41 pm     Reply with quote

Dear god it's working,

I can not describe in word how happy I am, Very Happy
Just one little question, how to do, to display scancodes (ex 0x45) instead of hex?

thank you so much for your answer.


Razz Razz Razz
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 3:59 pm     Reply with quote

Do you want to translate scan codes into the ASCII character for that
key ? Then you need a lookup table. Examples:
http://www.ccsinfo.com/forum/viewtopic.php?t=25673
http://www.ccsinfo.com/forum/viewtopic.php?t=27544
http://www.atmel.com/dyn/resources/prod_documents/DOC1235.PDF
Guest








PostPosted: Thu Aug 28, 2008 4:14 pm     Reply with quote

no not translate, just display them on hyperterminal as they are, like this "0x36" instead of hex.


thnx for the links

cheers
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 4:21 pm     Reply with quote

But a lot of them will be non-printable values. They will be control codes.
You were complaining about that before. You said that you got garbage
on the screen. That's why I suggested displaying them as ASCII hex
values.

I'm not sure what you want. You need to figure it out.
Guest








PostPosted: Thu Aug 28, 2008 4:28 pm     Reply with quote

when I say that hyperterminal was reading garbage, I realy ment garbage(only some signs where readible, the rest was heroglyfes), but what i want is to display scancode, controlcode, etc as they are, without translation.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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