Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I have saved the library and invoked it using #include "lib1.h" but I keep getting 6 errors.
the errors have something to do with BYTE, i and data not being valid identifiers. Can someone help me with the code and explain what does BYTE actually mean?
One more thing, since the PIC has no form of graphical output, what does this line actually do? printf("\r\nWaiting for a touch device...\r\n");
#include <16F628.h>
#include <stdio.h>
#use fixed_io(b_outputs=PIN_B4)
#use delay(xtal = 4000000)
#include "lib2.h"
void main()
{
BYTE buffer[8];
BYTE i;
while(1){
output_high(PIN_B4);
delay_ms(500);
output_low(PIN_B4);
delay_ms(500);
//printf("\r\nWaiting for a touch device...\r\n");
while(!touch_present()) ;
delay_ms(200);
if(touch_present()) {
touch_write_byte(0x33);
for(i=0;i<8;++i)
buffer[i]=touch_read_byte();
}
}
}
#ifndef TOUCH_PIN
#define TOUCH_PIN PIN_B0
#if defined(__PCH__)
#bit TOUCH_PIN_BIT = 0xF8A.0
#else
#bit TOUCH_PIN_BIT = 6.0
#endif
#endif
BYTE touch_read_byte() {
BYTE i,data;
for(i=1;i<=8;++i) {
output_low(TOUCH_PIN);
delay_us(14);
output_float(TOUCH_PIN);
delay_us(5);
shift_right(&data,1,input(TOUCH_PIN));
delay_us(100);
}
return(data);
}
BYTE touch_write_byte(BYTE data) {
BYTE i;
for(i=1;i<=8;++i) {
output_low(TOUCH_PIN);
delay_us(10);
if(shift_right(&data,1,0)) {
output_high(TOUCH_PIN);
delay_us(10);
if(!TOUCH_PIN_BIT)
return(0);
} else {
output_low(TOUCH_PIN);
delay_us(10);
if(TOUCH_PIN_BIT)
return(0);
}
delay_us(50);
output_high(TOUCH_PIN);
delay_us(50);
}
return(TRUE);
}
BYTE touch_present() {
BOOLEAN present;
output_low(TOUCH_PIN);
delay_us(500);
output_float(TOUCH_PIN);
delay_us(5);
if(!input(TOUCH_PIN))
return(FALSE);
delay_us(65);
present=!input(TOUCH_PIN);
delay_us(240);
if(present)
return(TRUE);
else
return(FALSE);
}
if(touch_present()) {
touch_write_byte(0x33);
for(i=0;i<8;++i)[COLOR="Blue"]{[/COLOR]
buffer[i]=touch_read_byte();
[COLOR="blue"]write_eeprom(i,buffer[i]);
}[/COLOR]
}
while(!touch_present()) ;
output_high(PIN_B4); // while ibutton not touched....turn on LED
delay_ms(200);
if(touch_present()) {
output_low(PIN_B4); // when ibutton touched... turn it off
#include <16F628.h>
#include <stdio.h>
#use fixed_io(b_outputs=PIN_B4)
#use delay(xtal = 4000000)
#include "lib2.h"
#use rs232(baud = 9600, xmit=PIN_B2, rcv=PIN_B1, stop=1,)
void main()
{
BYTE buffer[8];
BYTE i;
while(TRUE){
//printf("\r\nWaiting for a touch device...\r\n");
while(!touch_present()) ;
output_high(PIN_B4);
delay_ms(200);
if(touch_present()) {
output_low(PIN_B4);
touch_write_byte(0x33);
for(i=0;i<8;++i)
buffer[i]=touch_read_byte();
}
for(i=0; i<8; i++)
putc(buffer[i]);
}
}
void main()
{
BYTE buffer[8];
BYTE i;
while(TRUE){
//printf("\r\nWaiting for a touch device...\r\n");
while(!touch_present()); //wait for button to be missing
output_high(PIN_B4); //light LED
delay_ms(200);
if(touch_present()) { //if button is present
output_low(PIN_B4); //extinguish LED
touch_write_byte(0x33); //write command ReadRom
for(i=0;i<8;++i) //read the 8 byte ID
buffer[i]=touch_read_byte();
}
for(i=0; i<8; i++)
putc(buffer[i]);
}
}
void main()
{
BYTE buffer[8];
BYTE i;
while(TRUE){
//printf("\r\nWaiting for a touch device...\r\n");
while(!touch_present()); //wait for button to be missing...'as long as ibutton is
missing'
output_high(PIN_B4); //light LED
delay_ms(200);
if(touch_present()) { //if button is present
output_low(PIN_B4); //extinguish LED
touch_write_byte(0x33); //write command ReadRom
for(i=0;i<8;++i) //read the 8 byte ID
buffer[i]=touch_read_byte();
}
for(i=0; i<8; i++)
putc(buffer[i]);
}
}
Really?
Isn't that line saying 'as long as the ibutton is missing?'