I am writting a keyboard emulator for the pic microcontroller.
Unfortunately, after watching it on the oscilliscope, it is not
transmitting the right data. The clock signal on B1 is working correctly,
however, the actual data part is not. I've included this short snipet,
and the entire program, so anyone can peruse my work. Thanks for any and
all help.
for (i = 0; i<= 7; i++)
{
if ((buffer[curr] & y) == y)
// ^^ this line is the main problem I think.
{
parity = not(parity);
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y << 1;
}
Kyle
#include <16F874.H>
#use delay(clock=20000000)
#define ALLIN 0xFF
#define LiftC 0xF0
#define DirKey 0xE0
#define KeyTm 0x03
//ENTER UP LEFT DOWN RIGHT Q W 1
const char TBLP1[] = {0x5A, 0x75, 0x6B, 0x72, 0x74, 0x15, 0x1D, 0x16};
//5 A S D F G H 2
const char TBLP2[] = {0x36, 0x1C, 0x1B, 0x23, 0x2B, 0x34, 0x33, 0x1E};
int x;
int8 y;
int8 i;
int8 buffer[25];
int1 parity;
int8 buffsize;
int8 curr;
int8 next;
int8 load;
int8 P1;
int8 P2;
int8 P1Stat;
int8 P2Stat;
int1 Shift1;
int1 Shift2;
#byte PORTC = 6
#byte PORTD = 8
void buff_load()
{
buffsize++;
buffer[next] = load;
next++;
if (next == 25) next = 0;
}
//CLOCK on PIN B1
//DATA on PIN B0
void main()
{
curr = 0;
next = 0;
P1 = 0;
P2 = 0;
Shift1 = 0;
Shift2 = 0;
x = 0;
while(1)
{
set_tris_b(ALLIN);
set)tris_c(ALLIN); //Start Keyboard
//Test Key Values
P1Stat = PORTC;
/* if (!Input(PIN_C0) != bit_test(P1, 1))
{
}*/
x = 2;
for(i = 1; i <=7; i++)
{
if((not(P1Stat) & x) != (P1 & x))
{
if (i < 5)
{
load = DirKey;
buff_load();
}
if (bit_test(P1,x))
{
bit_set(P1,x);
}
else
{
bit_clear(P1,x);
load = LiftC;
buff_load();
}
load = TBLP1[i];
buff_load();
}
x << 1;
}
/* if (x == 1000 && P1 != 1)
{
P1 = 1;
load = TBLP1[7];
buff_load();
}
x++;*/
output_low(PIN_A0);
if (buffsize > 0)
{
//Test if keyboard is ready to transmit
while( !INPUT(PIN_B0) || !INPUT(PIN_B1))
{
}
delay_us(40);
//BEGIN TRANSMISSION
output_high(PIN_A0);
delay_ms(500);
parity = TRUE;
set_tris_b(KeyTm);
output_low(pin_B0);
delay_us(15);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y = 1;
for (i = 0; i<= 7; i++)
{
if ((buffer[curr] & y) == y)
{
parity = not(parity);
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
y << 1;
}
if (parity)
{
output_high(PIN_B0);
}
else
{
output_low(PIN_B0);
}
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
delay_us(15);
output_high(PIN_B0);
delay_us(24);
output_low(PIN_B1);
delay_us(40);
output_high(PIN_B1);
buffsize = buffsize - 1;
if (curr != 25)
{
curr++;
}
else
{
curr = 0;
}
} //if (buffsize > 0)
} //while(1)
} //void main() 6 2343
DarkKobold <no**@thanks.com> scribbled the following
on comp.lang.c: I am writting a keyboard emulator for the pic microcontroller. Unfortunately, after watching it on the oscilliscope, it is not transmitting the right data. The clock signal on B1 is working correctly, however, the actual data part is not. I've included this short snipet, and the entire program, so anyone can peruse my work. Thanks for any and all help.
for (i = 0; i<= 7; i++) { if ((buffer[curr] & y) == y) // ^^ this line is the main problem I think. { parity = not(parity); output_high(PIN_B0); } else { output_low(PIN_B0); } delay_us(24); output_low(PIN_B1); delay_us(40); output_high(PIN_B1); delay_us(15); y << 1;
I suspect the culprit is this line. It is calculating y << 1, i.e.
y * 2, and then throwing the result away. y is left unchanged. I
suppose you want y <<= 1.
(snip loads and loads of off-topic code)
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To err is human. To really louse things up takes a computer."
- Anon
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bm**********@oravannahka.helsinki.fi... DarkKobold <no**@thanks.com> scribbled the following on comp.lang.c:
<snip> for (i = 0; i<= 7; i++) { if ((buffer[curr] & y) == y) // ^^ this line is the main problem I think.
<snip>
y << 1;
Also, it appears that y is uninitialized when it is first used. It needs to
have a value before you use it the first time. You can't assume that it
starts at zero.
On 10/16/2003 3:18 PM, Not Really Me wrote: "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message news:bm**********@oravannahka.helsinki.fi...
DarkKobold <no**@thanks.com> scribbled the following on comp.lang.c:
<snip>
for (i = 0; i<= 7; i++) { if ((buffer[curr] & y) == y) // ^^ this line is the main problem I think.
<snip>
y << 1;
Also, it appears that y is uninitialized when it is first used. It needs to have a value before you use it the first time. You can't assume that it starts at zero.
Yes you can, it's static. See http://www.eskimo.com/~scs/C-faq/q1.30.html.
Ed.
On Thu, 16 Oct 2003 15:20:52 -0500, Ed Morton
<mo****************@Lucent.com> wrote: On 10/16/2003 3:18 PM, Not Really Me wrote: "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message news:bm**********@oravannahka.helsinki.fi...
DarkKobold <no**@thanks.com> scribbled the following on comp.lang.c:
<snip>
for (i = 0; i<= 7; i++) { if ((buffer[curr] & y) == y) // ^^ this line is the main problem I think.
<snip>
y << 1;
Also, it appears that y is uninitialized when it is first used. It needs to have a value before you use it the first time. You can't assume that it starts at zero.
Yes you can, it's static. See http://www.eskimo.com/~scs/C-faq/q1.30.html.
However, you want y to start at 1, so you still need to initialize it
immediately before entering the for() loop.
--
Peter Bennett VE7CEI
GPS and NMEA info and programs: http://vancouver-webpages.com/peter/index.html
Newsgroup new user info: http://vancouver-webpages.com/nnq
Not Really Me wrote: "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message news:bm**********@oravannahka.helsinki.fi... DarkKobold <no**@thanks.com> scribbled the following on comp.lang.c:
<snip> for (i = 0; i<= 7; i++) { if ((buffer[curr] & y) == y) // ^^ this line is the main problem I think. <snip> y << 1;
Also, it appears that y is uninitialized when it is first used. It needs to have a value before you use it the first time. You can't assume that it starts at zero.
The initialization did not appear in the extract at
the top, but you'll find it right there in plain sight
if you read the "complete" code later in the message.
-- Er*********@sun.com
"Eric Sosman" <Er*********@sun.com> wrote in message
news:3F***************@sun.com... Not Really Me wrote:
<snip>
The initialization did not appear in the extract at the top, but you'll find it right there in plain sight if you read the "complete" code later in the message.
You got me there. I did not read the full code. I see enough awful code
all day long doing software testing for safety critical apps. I just
couldn't bring myself to continue. Sadly it looks like all too much of the
"production" code that customers submit for validation.
--
Scott
Validated Software Corp. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Spamtrap |
last post by:
I only do occasional Perl programming and most things I write are
short processes. I have something I'm working on that is scanning a
text file with about 15 million lines and trying to extract...
|
by: aj902 |
last post by:
Hello ,
I am trying to create a program
where all detail,
http://www.albany.edu/~csi333/projects.htm
|
by: vgame64 |
last post by:
Hi, I have been struggling with writing a program for a few hours. The
requirements are that: """You will be writing a program which will
determine whether a date is valid in
terms of days in that...
|
by: robinsand |
last post by:
My apologies to those of you who are more advanced Visual C++ .NET
programmers, but I am working on a project for an MBA course that is
condensed into an eight-week schedule, and I need help...
|
by: pamelafluente |
last post by:
I am still working with no success on that client/server
problem. I need your help. I will submit simplified versions
of my problem so we can see clearly what is going on.
My model:
A client...
|
by: skumar434 |
last post by:
i need to store the data from a data base in to structure
.............the problem is like this ....suppose there is a data base
which stores the sequence no and item type etc ...but i need only...
|
by: naknak4 |
last post by:
Introduction
This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will...
|
by: naknak |
last post by:
Introduction
This assignment requires you to develop solutions to the given problem
using several different approaches (which actually involves using three
different STL containers). You will...
|
by: peterggmss |
last post by:
This is a slot machine game, 2 forms. One is the actual game (frmMachine) and the other is in the background and randomizes the images shown on frmMachine. I need to make frmMachine wait for...
|
by: raghavshastri |
last post by:
You are to write a C++ program to perform a statistical analysis of the blobs in an image. The image will be a grayscale image in PGM format for simplicity.
Here is a sample PGM image with 10...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |