![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi, I've bought the PICkit 1 and are now trying to programme the PIC12F675. Im using HI-TECH (HI-TIDE?) C to write to code and programme it to the chip with "PICkit 1 Classic". I want four of the pins on the chip to be input and two of them to be output, this should be possible right? To do this i've used: TRISIO = 0b11001111; But what should I then set GPIO to set the two outputs high/low? Thanks in advance! Mikkel *microchips! Last edited by mikkelbg; 24th February 2007 at 07:44 PM. | |
| |
| | (permalink) | |
| Quote:
bsf GPIO, GP4 ;To make bit 4 of GPIO high bsf GPIO, GP5 ;To make bit 5 of GPIO high bcf GPIO, GP4 ;To make bit 4 of GPIO low bcf GPIO, GP5 ;To make bit 5 of GPIO low In C this should work(Not sure on HighTech C): GP4 = 1; //To make bit 4 of GPIO high GP5 = 1; //To make bit 5 of GPIO high GP4 = 0; //To make bit 4 of GPIO low GP5 = 0; //To make bit 5 of GPIO low
__________________ --- The days of the digital watch are numbered. --- | ||
| |
| | (permalink) |
| That gives me the following error: undefined identifier "GP4". By reading posts on this site i understand that I somehow has to turn stuff like analog ports off, is that correct? Here's all the code in C (found it in the examples that came with the PICkit 1): Code: GPIO = 0; //Clear GPIO ANSEL = 0b00000000; // configure A/D inputs as digital I/O TRISIO = 0b11001111; //GPIO 3,4 outputs, GPIO 0,1,2,5,6,7 inputs OPTION = 0b11010000; // Timer0 internal clock, 1:2 prescale CMCON = 0b00000000; // configure comparator inputs as digital I/O GP4 = 1; //To make bit 4 of GPIO high | |
| |
| | (permalink) | |
| Quote:
CMCON = 0b00000000; // configure one comparator input as digital I/O to this: CMCON = 0b00000111; // configure all comparator inputs as digital I/O So that GP0 & 1 are IO only....
__________________ --- The days of the digital watch are numbered. --- | ||
| |
| | (permalink) |
| Looked in some of the header files and found no GP4, but did find GPIO(0-5), that might be it? It still dosn't work though. It almost seems like it's random (not only the two outputs but all the ports on the chip) which ports opens when changing the GPIO4 and GPIO5 to either 0 or 1. Here is the full sourcecode: main.c Code: #include <htc.h>
#include "main.h"
void
main(void)
{
Init(); //Initalize the chip
while (1){
GPIO4 = 1; //To make bit 4 of GPIO high/low
GPIO5 = 1; //To make bit 5 of GPIO high/low
}
}
void Init(void)
{
#asm
call 0x3FF //Load Factory Calibration Value Into OSCCAL
bsf _STATUS,5 //BANK1
movwf _OSCCAL
#endasm
ANSEL = 0b00000000; // configure A/D inputs as digital I/O
TRISIO = 0b11001111; //GPIO 3,4 outputs, GPIO 0,1,2,5,6,7 inputs
OPTION = 0b11010000; // Timer0 internal clock, 1:2 prescale
CMCON = 0b00000111; // configure all comparator inputs as digital I/O
} Code: #ifndef MAIN_H_ #define MAIN_H_ #include <pic.h> __CONFIG(UNPROTECT & BOREN & MCLRDIS & PWRTEN & WDTDIS & INTIO); void Init(void); #endif /*MAIN_H_*/ Mikkel | |
| |
| | (permalink) |
| You may try this: Code: #include <htc.h>
#include "main.h"
void main(void)
{
Init(); //Initalize the chip
while (1){
GPIO0 = 1; //To make bit 0 of GPIO high/low
GPIO1 = 1; //To make bit 1 of GPIO high/low
}
}
void Init(void)
{
#asm
bsf STATUS, RP0 ;Bank 1
call 3FFh ;Get the cal value
movwf OSCCAL ;Calibrate
bcf STATUS, RP0 ;Bank 0
#endasm
CMCON = 0b00000111; // configure all comparator inputs as digital I/O
ANSEL = 0b00000000; // configure A/D inputs as digital I/O
TRISIO = 0b111100; //GPIO0-1 outputs GPIO2-3-4-5 inputs
OPTION = 0b11011000;
} | |
| |
| | (permalink) |
| I didn't use GPIO3? Shouldn't it be possible to use GPIO4 and 5 as outputs? EDIT: Oh sorry, did - will try it out | |
| |
| | (permalink) |
| You can use GPIO4-5 as outputs EDIT: you didn't use GPIO3, but the comment after TRISIO confused me: TRISIO = 0b11001111; //GPIO 3,4 outputs, GPIO 0,1,2,5,6,7 inputs I think that the calibration routine was the issue. Last edited by eng1; 28th February 2007 at 05:42 PM. | |
| |
| | (permalink) |
| It works!! Thanks! Can I use GPIO to read from the inputs as well? Last edited by mikkelbg; 28th February 2007 at 05:42 PM. | |
| |
| | (permalink) |
| Yes, you can check an input with an if instruction. For example: Code: if (GPIO0==0)
// do something | |
| |
| | (permalink) |
| Great thanks! Do you also have some code that is able to make a delay? Currently i'm using this: void Delay(char value) { for (outer=value; outer != 0; outer--) { for (inner=0x57; inner != 0; inner--) //0xAF { } } return; } But isn't precise enough to control a servo motor. | |
| |
| | (permalink) |
| Doesn't your C compiler have a Delay() function?. | |
| |
| | (permalink) | |
| Quote:
By the way, do you want the delay to be exact? This is not always required. If you want precise timing, you can use a TIMER and interrupts. Last edited by eng1; 14th March 2007 at 08:41 PM. | ||
| |
| | (permalink) |
| Nigel Goodwin -> How should the Delay function work? Delay(milliseconds) ? eng1 -> Yes it needs to be precise. I'm going to control a servo with it, so I need to be able to make a pause less than a millisecond. | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Most Common and Best PIC? | LiquidOrb24 | Micro Controllers | 13 | 12th February 2007 03:42 AM |
| Good Pic Book Recomendations | BackFire1 | Micro Controllers | 13 | 5th February 2007 11:20 PM |
| PIC 16F628A UART Coding Problem | Gayan Soyza | Micro Controllers | 11 | 1st February 2007 12:59 PM |
| Questions from a beginner in electronics... | Shocks McTool | General Electronics Chat | 8 | 21st November 2005 03:01 AM |
| Newcomers, please read! (PIC regarded) Upd. 0xD | Jay.slovak | Micro Controllers | 0 | 17th April 2005 02:05 PM |