Date: Thu, 29 May 1997 07:08:52 EST From: Glen Benson Subject: New To PIC What am I doing wrong? Hi, I am new to PIC, cant get a handle on asm fast enough. So I bought a basic compiler. I can write all sorts of neat things I dont need to do, But I cant get the following code to work in less than about 2 seconds. I need to take an ADC reading stuff it in to a varible and send it to the PC via lpt port. For my test I use qbasic and turn on Pin 7 of the PIC with the (out lpt,1 statement) then I read the level of pin 6 on the pick to see if hi or low then I shift the value in B0 , and do it 7 more times. I have to put 2 second delays in the qbasic code to make it work. Thats .5 hz (its got to go faster than that). Please if you see my blunder, can you show me? :) ' a qbasic program turns on PIN 7, then the qbasic prog. reads ' the value on (lpt pin10) connected to (PIC on PIN 6) and repeats ' 8 times toget the whole byte. The qbasic prog has to have ' 2 second delays to get the right data. How could this ' be written better? It cant get worse. Symbol DDIR = Dir6 ' Shift data pin direction is Dir1 Symbol DPIN = Pin6 ' Shift data pin is 6 Symbol CPIN = 1 ' Shift clock pin is 1 input 7 ' Make pin 7 an input START: B0=65 ' value to shift out loop: pause 1 'didnt seem to work without this if pin7=1 then getbit ' pin 1 from lpt just went high goto loop getbit: DDIR = 1 ' set the direction of the pin DPIN = bit0 ' get the bit send it out to pin 10 on lpt B0=B0/2 ' shift the value in B0 over goto loop Thanks Glen Benson ------------------------------ Glen, Try changing your code to this. loop: if pin7=1 then getbit ' pin 1 from lpt just went high goto loop getbit: DDIR = 1 ' set the direction of the pin DPIN = bit0 ' get the bit send it out to pin 10 on lpt B0=B0/2 ' shift the value in B0 over if pin7=0 then loop ' wait for Pin 7 to go low before looking for new bit Essentially you are implementing a synchronous data transfer, with the PC providing the clock. It looks like your original code would sense the first clock pulse and then shift out a bunch of bits before the second clock pulse. The extra IF should keep you in sync. If you want to speed it up a bit more, send byte wide or nibble wide data for every PIN 7 clock pulse. You have up to 9 input pins on a standard parallel port. So the limit is the number of pins available on your PIC. Let me know how it goes, Paul Kolesnikoff pkolesni@ball.com