Gallery, Projects and General > Project Logs |
X2 X-axis Stepper motor Power Feed - (possible CNC conversion?) |
<< < (9/19) > >> |
John Rudd:
--- Quote from: craynerd on January 05, 2010, 03:37:32 AM ---Just curious John, what sort of stuff have you done with PICs? Chris --- End quote --- Chris, Hex code isnt something new to me, I used it lots for receiving encrypted tv during the D2MAC days... As for pics, I've built a number of pic based projects from magazines, infra red control for one...Most recent project which still isnt complete is a tacho for my 9*20 lathe...based on a 16F628A and a 2 line lcd display.. I'll post up photos ( nearly said pics.... :D ) when its done.. |
raynerd:
Hi John, I look forward to seeing the tacho - I`d be interested in making one so please post plenty of photos and details - obviously unless it is a commercial idea. I`m going to post up again shortly. I`ve just spent this evening making a little ball and cup game! I can`t help myself. I love these things!! Chris |
raynerd:
This is totally pointless (not like the dice wasn`t!!) but again I`ve learnt a lot from it, specifically using functions. It is based on the old Ball and Cup game - you know the one where you have to select which cup the ball is under. Basically, there are three buttons and the first row of leds lights to show your selection. The top row then starts to count and then stops on the computer selection (or under which cup the ball actually was!). If you match the leds, you win and the leds flash. If you don`t you lose and the leds come on solid and then reset. My issue is that I have used a lot of messy delay code in my "void CupDisplay" function. Anyone know a better way to do it? OHHH and OK before anyone says --- that is it now, back on task with the X-axis controller!!!!! --- Quote ---// define which pins our buttons are on #define button1 PORTA.b0 #define button2 PORTA.b1 #define button3 PORTA.b2 #define YourLED1 PORTB.b0 #define YourLED2 PORTB.b1 #define YourLED3 PORTB.b2 // 3 buttons 1,2,3 linked to YourLED1, YourLED2, YourLED3 // When button is pressed corresponding LED lights and computer counts CupLED1-3 // CupLED1-3 lights. // if YourLED = CupLED you win - flashing. Game Resets // else...you loose. Game Resets char buttonPressed; // a variable that saves our button press char cup; char LED[4] = {0b00000000, 0b00000001, 0b00000010, 0b00000100}; void cupDisplay () { PORTC = 0b00000001; delay_ms(300); PORTC = 0b00000010; delay_ms(300); PORTC = 0b00000100; delay_ms(400); PORTC = 0b00000010; delay_ms(400); PORTC = 0b00000001; delay_ms(400); PORTC = 0b00000010; delay_ms(500); PORTC = 0b00000100; delay_ms(500); PORTC = 0b00000010; delay_ms(500); PORTC = 0b00000001; delay_ms(650); PORTC = 0b00000010; delay_ms(750); PORTC = LED[cup]; delay_ms(1000); if (buttonPressed == cup) { PORTC = 0b00000111; PORTB = 0b00000111; delay_ms(250); PORTC = 0b00000000; PORTB = 0b00000000; delay_ms(250); PORTC = 0b00000111; PORTB = 0b00000111; delay_ms(250); PORTC = 0b00000000; PORTB = 0b00000000; delay_ms(250); PORTC = 0b00000111; PORTB = 0b00000111; delay_ms(250); PORTC = 0b00000000; PORTB = 0b00000000; delay_ms(250); PORTC = 0b00000111; PORTB = 0b00000111; delay_ms(250); PORTC = 0b00000000; PORTB = 0b00000000; delay_ms(250); } else { PORTB = 0b00000111; PORTC = 0b00000111; delay_ms(2000); } } char ReadButtons () { if (button1) return 1; if (button2) return 2; if (button3) return 3; return 0; } void main() { char count; // misc use int adc; // somewhere to put the ADC we read // PIC's have lots of hardware - in this case in order to use PORTB // we have to turn off the ADC's // All ports digital ADCON1 = 0x0F; CMCON = 0x07; // set all the pins on PORT B to 'off' before we start PORTA = 0; PORTB = 0; PORTC = 0; // set the tri-state buffer. Pins set to '1' are input, '0' are output // we've done this in binary to make it easier to see // each number is 1 pin, right hand is pin 0, left is pin 7 TRISA = 0b11111111; TRISB = 0b00000000; TRISC = 0b00000000; // ============= Code Proper Starts ======== while (1) // loop forever { while (!(buttonPressed = ReadButtons() )); cup = 1; while (ReadButtons()) // counts while buttons are pressed { cup++; if (cup > 3) cup = 1; } if (buttonPressed == 1) { YourLED1 = 1; cupDisplay (); } if (buttonPressed ==2) { YourLED2= 1; cupDisplay (); } if (buttonPressed ==3) { YourLED3= 1; cupDisplay (); } PORTA = 0; PORTB = 0; PORTC = 0; } } --- End quote --- |
Bernd:
:offtopic: Hey Chris, what ever happened to the clock you were building? :offtopic: :poke: Bernd |
raynerd:
lol, it is warmer up here in the living room programming these pics on my PC than in the workshop. I actually can`t open the door to the shop at the moment with all this snow!!! Naaa, not really the excuse, if I`d wanted to I`d have carried on. I`ve just got a bit of a bee in my bonnet about these PICs at the moment, I find them amazing. My clock is my life ambition, it will be done there is no fear of that! |
Navigation |
Message Index |
Next page |
Previous page |