Author Topic: my first project and experience debuging hardware  (Read 28037 times)

0 Members and 1 Guest are viewing this topic.

Offline Ferroto

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: ca
my first project and experience debuging hardware
« on: October 26, 2009, 11:25:01 am »
I'm a software guy making his first attempt in electronics, I've been playing around with the pickit2 for about a week now and my first project was making an LED light, several hours later I lit the LED :D

So naturaly my next project was a 7 segment LED display I'd been eyeing a datasheet and based on the pinout i wrote a table of hex values and a pinout that to my surprise worked out of the box my code proply drove the LED display. then came problems...

It would only count to 3 then reset after scratching my head followed by bashing my head against the counter I found an article about watchdog timers and disabling the WDT worked then i of course wanted to include a button and have the button change the digits instead of a timer and I've never done any electronics seriously before i know some basic stuff like diodes only pass current 1 way etc... I hooked up a switch between the +3v supply the other was connected to ra3 which did nothing. so i started to google examples of PIC based projects that included buttons and sure enough my code was ok but I was missing a pulldown resistor. Either ways everything's working now and heres the code for anyone who's interested

LED.h (LED driver)
Code: [Select]
int led_digit1(int dig, int DP)
TRISC = 0;
if (dig == 1){PORTC = 0x60;}
if (dig == 1. && DP == 1){PORTC = 0x61;}
if (dig == 2){PORTC = 0xda;}
if (dig == 2. && DP == 1){PORTC = 0xdb;}
if (dig == 3){PORTC = 0xf2;}
if (dig == 3. && DP == 1){PORTC = 0xf3;}
if (dig == 4){PORTC = 0x66;}
if (dig == 4. && DP == 1){PORTC = 0x67;}
if (dig == 5){PORTC = 0xb6;}
if (dig == 5. && DP == 1){PORTC = 0xb7;}
if (dig == 6){PORTC = 0x3e;}
if (dig == 6. && DP == 1){PORTC = 0x3f;}
if (dig == 7){PORTC = 0xe0;}
if (dig == 7. && DP == 1){PORTC = 0xe1;}
if (dig == 8){PORTC = 0xfe;}
if (dig == 8. && DP == 1){PORTC = 0xff;}
if (dig == 9){PORTC = 0xf6;}
if (dig == 9. && DP == 1){PORTC = 0xf7;}
if (dig == 0){PORTC = 0xfc;}
if (dig == 0. && DP == 1){PORTC = 0xfd;}

Code: [Select]
#include <pic.h>
#include "c:\lib\LED.h"    //LED driver

void t_loop(int d)            //Timer
{                                  //Timer
while (d != 0)                //Timer
{d = d - 1;}                 //Timer
}                                //Timer

int main (void)
TRISA = 1;
ANSEL = 0;
int a;
int c = 0;

while (1 == 1)                           //Infinite loop
if (1 == RA3)                             //Is the button pressed
c = c+1;                    //adds 1 to c where c = what's displayed
if (c == 10){c = 0;}    //Theres only 1 digit so if it turns 10 it'll turn 0 before the display trys to display a 10 which it can't
led_digit1(c,0);           //Display value of c on the display
t_loop(100000);          //Pauses for 100,000 loops equlivent to aprox 1 sec on pic16f690
led_digit1(c,0);                           //Continuous display of current digit (gets called everytime the infinate loop repeats


LED Digikey part # 67-1476-ND
« Last Edit: October 26, 2009, 12:12:25 pm by Ferroto »

Offline EEVblog

  • Administrator
  • *****
  • Posts: 32192
  • Country: au
    • EEVblog
Re: my first project and experience debuging hardware
« Reply #1 on: October 26, 2009, 08:45:00 pm »
Nice step-by-step experimentation/debugging, that's how you learn.

One of the traps with PIC (and almost all micros) are that the pins can all do many things, and also registers that must be set up first as you've found out, and you have to set them up to do what you want first at the start of your program.
e.g. some pins are set to ADC inputs by defaults
This can often lead to hours of frustration just to light a LED.

This is the advantage of say PICAXE, Arudino, and other development platforms designed for beginners, they just work first go compared with raw microcontrollers like the PIC.

Did you know the PIC has built in pull-up resistors you can use with switches?


Offline septer012

  • Regular Contributor
  • *
  • Posts: 67
  • Country: us
Re: my first project and experience debuging hardware
« Reply #2 on: October 27, 2009, 04:29:52 pm »
I know I shouldnt reply to a hijacked thread, but sweet job on the chess board.  There is really no reason to use RFID tags to identify each peice if you can store and keep record of every peice from the beginning you know what has been picked up and put back down, you can keep track if you start from a brand new game

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo