Skip to Content
Hardware Hacking Projects for Geeks
book

Hardware Hacking Projects for Geeks

by Scott Fullam
January 2004
Intermediate to advanced
348 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Hardware Hacking Projects for Geeks
261
Chapter 13, How to Make RC Cars Play Laser Tag
Exhibit B: RC Car Hack Software Code
// radio control car hack
// (4/26/03 Scott Fullam
// feel free to modify this code
#include <P16F876A.h>
#define var_res_clk 0x01
void gen_2khz(int cycles);
void init_code();
void check_hit();
void check_fire();
char hit_count;
char shot_count;
void update_score(char num);
#pragma CLOCK_FREQ 1600000
// #pragma RESERVE_ADDR_0 // add this line back in if you are using the ICD2 and debugging code
void main()
{
init_code();
while(1)
{
check_fire();
check_hit();
}
}
void init_code()
{
// set pr2 divider to 25. this plus the prescaler value of 4 will generate
// a 38461 kHz out from CPP1 using a system crystal of 16 MHz
pr2 = 25;
ccpr1l = 0x0D;
// set the diver bits but do not set PWM mode yet
ccp1con = 0x00;
// set up portc 2 as an output, 0,1 as inputs
trisc = 0x03;
// set prescaler to 4 and switch timer 2 on
t2con = 0x05;
// porta 2-5 as outputs. the others as inputs
// set adcon1 so that all pins are digital I/O
adcon1 = 0x07;
trisa = 0x00;
// set up timer1 for 2 kHz (or 3 kHz) modulation generation
t1con = 0x20;
hit_count = 0;
Exhibit B
ch13_rc.indd 261
1/22/2002 4:44:43 PM
262
Part II: Advanced Hacks, Tools, and Techniques
shot_count = 15;
porta = 0x00;
}
void gen_2khz(int cycles)
{
int i;
char temp1;
for (i = 0; i < cycles; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Home Hacking Projects for Geeks

Home Hacking Projects for Geeks

Eric Faulkner, Tony Northrup

Publisher Resources

ISBN: 0596003145Catalog PageErrata