View previous topic :: View next topic |
Author |
Message |
smita.g
Joined: 20 Sep 2015 Posts: 7
|
pic10f220 general |
Posted: Mon Sep 28, 2015 10:04 pm |
|
|
Hello Sir,
I am using CCS PCB C Compiler version 4.104 48488
I am using pic10f220 controller, And not able put high GPIO2.
here port pin B0 & B3 are use as analog pin while B1 & B2 use as digital pins.
Here is the code for your reference.
Code: |
#delay 8000000
#define PIN_B2 50
voi main()
{
setup_adc_ports(sAN0);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);
OUTPUT_HIGH(PIN_B2);
while(TRUE)
{
OUTPUT_HIGH(PIN_B2);
}
} | Please give me suggestions.
Thanks in advance. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
smita.g
Joined: 20 Sep 2015 Posts: 7
|
pic10f220 general |
Posted: Tue Sep 29, 2015 3:17 am |
|
|
Hello,
I have use this in my code, but still could not set this port pin high.
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM} |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Tue Sep 29, 2015 5:29 am |
|
|
So have you used it in the main as shown?. |
|
|
smita.g
Joined: 20 Sep 2015 Posts: 7
|
pic10f220 general |
Posted: Tue Sep 29, 2015 9:42 pm |
|
|
Yes following code for your referene
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
#delay 8000000
#define PIN_B2 50
voi main()
{
set_options(0xC7);
setup_adc_ports(sAN0);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);
OUTPUT_HIGH(PIN_B2);
while(TRUE)
{
OUTPUT_HIGH(PIN_B2);
}
} |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Wed Sep 30, 2015 12:25 am |
|
|
OK.
You are turning it off after you set it....
The point is the 'option' setting, also sets up the timer. You then setup the timer, which turns off the required option....
As a general comment, include the processor file, and then your pins are defined. So:
Code: |
#include <10F220.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCPU //Master Clear Pull-up disabled
#FUSES IOSC8 //INTOSC speed 8MHz
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=8000000)
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
void main()
{
set_options(0xC7); //setup timer and WDT
setup_adc_ports(NO_ANALOGS); //why are you connecting AN0 to the multiplexor
//and then disabling the ADC?.
setup_adc(ADC_OFF);
OUTPUT_HIGH(PIN_B2);
while (TRUE)
{
delay_ms(100);
output_toggle(PIN_B2);
}
}
|
This runs and correctly toggles the pin. |
|
|
smita.g
Joined: 20 Sep 2015 Posts: 7
|
pic10f220 general |
Posted: Wed Sep 30, 2015 3:07 am |
|
|
This is my actual code. I want to generate pulse as per analog input.
So I have configure timer for 1mSec frequency. AN0 will be one analog input, digital output will be on B2.
I want to generate 3v = 40Hz frequency on B2 pin. I have attached resistor pot to AN0.
But I am stuck, because I could not even set B2 high.
Now I will try your code as it is, and let inform you soon.
Following code for your reference.
Code: |
#include <10F220.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCPU //Master Clear Pull-up disabled
#FUSES IOSC8 //INTOSC speed 8MHz
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=8000000)
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
void main()
{
set_options(0xC7); //setup timer and WDT
/*I want timer0 for 1msec, AN0 analog input, GPIO 1 & 2 will be output*/
#ASM \
movlw 0xF9 \
movwf 0x1 \
movlw 0x9 \
movwf 0x6 \
movlw 0x41 \
movwf 0x7 \
#ENDASM
while (TRUE) //just for check
{
OUTPUT_HIGH(PIN_B2);
}
while (TRUE)
{
adcRData = read_ADC();
ActualFreq = 3825/adcRData;
generate_pulse();
}
}
void generate_pulse()
{
unsigned char current;
current= GET_Timer0();
if(current == 0)
{
k++;
if(k>ActualFreq)
{
k=0;
output_toggle(PIN_B2);
}
SET_Timer0(249);
}
}
|
Thanks for help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Wed Sep 30, 2015 4:19 am |
|
|
To give 1mSec overflow on the clock, you would want the clock to be fed off a 4uSec clock. Since the prescaler is fed from Fosc/4, this is an /8 division. Change the value used in set_option to 0xC2, and the timer will overflow at about 1mSec (2 gives /8).
8000000/(4*8*256) = 976*/second.
So:
Code: |
set_options(0xC2); //setup timer and WDT
//Key point to understand is that the timer and watchdog _share_
//these settings, the both settings also controls the I/O pin.
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_4);//enable
set_adc_channel(0);
|
This gives ADC on pin A0, ADC enabled, Timer overflowing at 1mSec. |
|
|
smita.g
Joined: 20 Sep 2015 Posts: 7
|
pic10f220 general |
Posted: Wed Sep 30, 2015 5:25 am |
|
|
Hello Sir,
I have did the correction according to your suggestion about the timer(as per just above code).
But still questions is how to check it on DSO without using port pin?
I have tried your code(previous) as well,but still i could not toggle the port pin.
I didnt understand where to check?
-Smita. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Wed Sep 30, 2015 5:39 am |
|
|
Are you absolutely sure that B2 is not shorted somewhere?.....
If it is programmed as an input (which is what it defaults to), there is no reason you can't pull it up/down with a resistor to the supply rails. If it doesn't go up, then you have found your problem..... |
|
|
|