Hello Guys
i've moved to learning embedded C with help of a friend
but need some help with my project some ideas will be great
im using 4 7segment digits & sometimes i want to use 2 of them as a countdown counter & the others for display functions & in setting mode i want to use the 4 together to indicate
some functions like "open,Pro1,......"
thx for help
But im new to C so i couldnt understand anything hahahaha
anyway i need an idea to look for a solution for it
& BTW i have a problem if u use mikroC
in the examples there is ansel & anselh which as said disable all peripherals on ports
it gives me error when i try to compile any code usin ANSEL & ANSELH
other thing i've got stuck with interrupts & timer use
any good explained tutorial for this will b nice
much easier to help when you see the schematics, know which mcu used, with compilier. I provided an example for STM8. Anyway, you should not get any throuble to write zero to ansel register to disable analog functions.
Actualy, only one thing you need is a datasheet. There are clearly explained how to work with registers and so on.
im just trying an example to unerstand timer & interrupt
but it gives me errors when i compile it
here is the code
Code:
/*Header******************************************************/
unsigned cnt; // Define variable cnt
void interrupt() {
cnt++; // Interrupt causes cnt to be incremented by 1
TMR0 = 96; // Timer TMR0 is returned its initial value
INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared
}
void main() {
OPTION_REG = 0x84; // Prescaler is assigned to timer TMR0
ANSEL = 0; // All I/O pins are configured as digital
ANSELH = 0;
TRISB = 0; // All port B pins are configured as outputs
PORTB = 0x0; // Reset port B
TMR0 = 96; // Timer T0 counts from 96 to 255
INTCON = 0xA0; // Enable interrupt TMR0
cnt = 0; // Variable cnt is assigned a 0
do { // Endless loop
if (cnt == 400) { // Increment port B after 400 interrupts
PORTB = PORTB++; // Increment number on port B by 1
cnt = 0; // Reset variable cnt
}
} while(1);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*Header******************************************************/
unsigned cnt; // Define variable cnt
void interrupt() {
cnt++; // Interrupt causes cnt to be incremented by 1
TMR0 = 96; // Timer TMR0 is returned its initial value
INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared
}
void main() {
OPTION_REG = 0x84; // Prescaler is assigned to timer TMR0
ANSEL = 0; // All I/O pins are configured as digital
ANSELH = 0;
TRISB = 0; // All port B pins are configured as outputs
PORTB = 0x0; // Reset port B
TMR0 = 96; // Timer T0 counts from 96 to 255
INTCON = 0xA0; // Enable interrupt TMR0
cnt = 0; // Variable cnt is assigned a 0
do { // Endless loop
if (cnt == 400) { // Increment port B after 400 interrupts
PORTB = PORTB++; // Increment number on port B by 1
cnt = 0; // Reset variable cnt
}
} while(1);
}
Special function registers like ANSEL or OPTION_REG are specific for a processor. With an industry standard C compiler like GNU C or Microchip XC8 you use header files to select the processor and define these objects. I'm not using mikroC, as far as I know, the processor specific definitions are automatically included when you select a processor in the project manager.
You can review the mikroC user manual for the meaning of volatile. As far as I understand it's not required with the specific usage of variable cnt. But in case of doubt, you should use it for all variables that are modified in interrupt and read in the main code.
the error im talking about its
undeclred identifier 'ANSEL' in expression
undeclred identifier 'ANSELH' in expression
its working the port B without the ANSEL & ANSELH as digital output
i've used this as its included in the example of mikroC programming
- - - Updated - - -
Any good explained timer & interrupt routines will be great
what they mean by that the timer works in the back scenes i've used delay routines with assembly before & have included any inputs i want to check within the delay routine
how it works with timer & interrupts?
thx guys
ANSEL and ANSELH are registers in the PIC16F887 (as in the diagram) but my guess is you have selected a different processor in the compiler configuration. They do not exist in some other types of PIC so they may not be cross-referenced to an address if the wrong type was selected.