-
timer 1 for 16f627
Hi guys i am very new to c code language and i am just now writing my first code with the velleman p8048 programming kit and i am trying to program the 16f627. what i want to do is have a timer be started by the input (rao) but i want the timer to leave (portb) on for 20-30 seconds. is this even possible. if it is possible i want it to reset after 30 seconds. please can anyone help i am very new to programming and i need much help. i can get the (portb) light to turn on i just want it to turn on for 30 seconds thanks and here is my
Code:
#include <conio.h>
#define SW1 0x00;
__CONFIG (0x3F61);
void main (void)
{
CMCON = 0x07;
TRISA = 0xFF;
TRISB = 0;
PORTB = 0x01;
while ( 1 )
{
if(RA0 == 1)
PORTB = 0b000001;
else
PORTB = 0b000000;
}
}
-
What compiler are you using? There should be pre-defined functions, in the compiler documentation, for accessing/using the internal timers of the device.
-
thank you for your response I am using the mplab ide compiler with HiTech
-
I don't know if you can access the timer modules directly in HI-TECH C, but you can achieve the same results with the "__delay_ms(x)" function. To use this, you need to define a preprocessor symbol to represent the frequency of your oscillator.
The specifics can be found in the manual (here). If you haven't already, save this on your drive for future reference. And read through it, too!
If you have further questions, provide your updated code and ask away!
-
thank you guys so much i should be able to figure this out from here this is very exciting :)
-
okay so i defined my frequency but i cannot get it to compile
Code:
#include <htc.h>
#include <stdio.h>
#define SW1 0x00;
#define _XTAL_FREQ 4000000;
__CONFIG (0x3F61);
void main (void)
{
CMCON = 0x07;
TRISA = 0xFF;
TRISB = 0;
PORTB = 0x01;
while ( 1 )
{
if(RA0 == 1)
PORTB = 0b000001;
__delay_ms(9000);
else
PORTB = 0b000000;
}
}
-
Why can't you get it to compile?
If you have compiler errors then post the complete error messages exactly as they appear in your development environment.
Jim
-
Code:
#define SW1 0x00;
#define _XTAL_FREQ 4000000;
Get rid of those semi-colons. And do as jimblumberg said.
-
this is the error message I am getting
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\Jeremy\Desktop\test\test2,c.cce".
Clean: Done.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC-Lite\9.50\bin\picl.exe" -C -E"test2,c.cce" "test2,c.c" -O"test2,c.obj" -Zg9 -O -ASMLIST -Q -MPLAB -16F627
Halting build on first failure as requested.
BUILD FAILED: Wed Mar 06 12:34:54 2013
-
Have you been able to successfully compile anything before this? I'm fairly sure this has more to do with the configuration of your environment than the code. Search the internet, you'll find a lot of information on this topic.
Also see if you can open the *.cce file in a text editor (located in the project directory) - it might provide more specific information.
-
yes i can compile if i delete the delay_ function and it will compile and run on my velleman board
-
I'm assuming you removed the semi-colons as I mentioned in post #8.
I don't know the upper limit, but the delay function will give an error if the delay period is too large. Try it again with a smaller value (like 200) and see if it compiles.
-
Two issues; one C code issue.
Code:
if(RA0 == 1)
PORTB = 0b000001;
__delay_ms(9000);
else
PORTB = 0b000000;
I added the missing braces below.
Code:
if(RA0 == 1) {
PORTB = 0b000001;
__delay_ms(9000);
} else
PORTB = 0b000000;
Second __delay_ms has a limit of a value between 100 to 200.
Note: This limit was removed in recent Hi_tech C compiler versions.
Third, You need to use a define or use the Pro version to get __delay_ms to work.
I forget the define/prototype that is needed.
Edit: Found this in past Student's work. My MPLAB/HiTech C installation is bad so can not test if the is all that is needed.
Code:
#define _XTAL_FREQ 4000000
void _delay_ms(unsigned long n); //define a delay of n milliseconds
//Note that this is built into HiTech C but is limited to 197 msec for an unknown reason
Tim S.