|
|
View previous topic :: View next topic |
Author |
Message |
xbrav
Joined: 17 Feb 2009 Posts: 3
|
Getting started with PIC16F628A |
Posted: Tue Feb 17, 2009 2:12 am |
|
|
Hello all,
I am a beginner PIC programmer, so please excuse my lack of knowledge on the subject.
Wrote my first simple PIC program, simply output HIGH on all ports.
However, RA4/TOCKI/CMP2 (PIN_A4) is low, RA5/MCLR/VPP (PIN_A5) is floating (appears open), and CLKOUT (PIN_A6) is outputting the clock pulse.
Code: |
#include <16F628A.h>
#fuses NOMCLR,NOPROTECT,NOWDT,INTRC
void main()
{
set_tris_a(0x00);
set_tris_b(0x00);
while (1)
{
output_high(PIN_A0);
output_high(PIN_A1);
output_high(PIN_A2);
output_high(PIN_A3);
output_high(PIN_A4);
output_high(PIN_A5);
output_high(PIN_A6);
output_high(PIN_A7);
output_high(PIN_B0);
output_high(PIN_B1);
output_high(PIN_B2);
output_high(PIN_B3);
output_high(PIN_B4);
output_high(PIN_B5);
output_high(PIN_B6);
output_high(PIN_B7);
}
} |
I am very familiar with C, but do not understand the concept of fuses. I apologize if another topic describes it, but I've had no luck in the search. Thanks!
*EDIT*
OK I understand the issue with A4 being the drain pin, thus nothing will come off.
Basically, I've written a more complex code that does work, minus these output issues. CLKOUT I want to be an output with defined values. Same with MCLR. Is this possible? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 17, 2009 11:57 pm |
|
|
Quote: | However, RA4/TOCKI/CMP2 (PIN_A4) is low, RA5/MCLR/VPP (PIN_A5) is floating (appears open), and CLKOUT (PIN_A6) is outputting the clock pulse. |
See below for an explanation of pins A5 and A6.
Look in the 16F628A data sheet,
http://ww1.microchip.com/downloads/en/DeviceDoc/40044F.pdf
in this section:
Quote: |
TABLE 3-2: PIC16F627A/628A/648A PINOUT DESCRIPTION
|
It tells you all the available modes for each pin, and if are
input-only, i/o, open-drain, etc.
Certain pins are configured by Config bit settings (CCS calls them fuses).
Look in this section for a description of the Config bits and how they
affect the pins.
Quote: | REGISTER 14-1: CONFIG – CONFIGURATION WORD REGISTER |
Look at this Config bit for the MCLR pin:
Quote: | bit 5: MCLRE: RA5/MCLR/VPP Pin Function Select bit
1 = RA5/MCLR/VPP pin function is MCLR
0 = RA5/MCLR/VPP pin function is digital Input, MCLR internally tied to VDD |
This corresponds to the CCS fuse settings for MCLR and NOMCLR.
Look at these Config bits for the Internal oscillator:
Quote: | bit 4, 1-0: FOSC<2:0>: Oscillator Selection bits (4)
101 = INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
100 = INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN |
These correspond to the fuse settings of INTRC and INTRC_IO. |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Mon Jun 05, 2017 7:55 am |
|
|
PCM programmer wrote: | Quote: | However, RA4/TOCKI/CMP2 (PIN_A4) is low, RA5/MCLR/VPP (PIN_A5) is floating (appears open), and CLKOUT (PIN_A6) is outputting the clock pulse. |
See below for an explanation of pins A5 and A6.
Look in the 16F628A data sheet,
http://ww1.microchip.com/downloads/en/DeviceDoc/40044F.pdf
in this section:
Quote: |
TABLE 3-2: PIC16F627A/628A/648A PINOUT DESCRIPTION
|
It tells you all the available modes for each pin, and if are
input-only, i/o, open-drain, etc.
Certain pins are configured by Config bit settings (CCS calls them fuses).
Look in this section for a description of the Config bits and how they
affect the pins.
Quote: | REGISTER 14-1: CONFIG – CONFIGURATION WORD REGISTER |
Look at this Config bit for the MCLR pin:
Quote: | bit 5: MCLRE: RA5/MCLR/VPP Pin Function Select bit
1 = RA5/MCLR/VPP pin function is MCLR
0 = RA5/MCLR/VPP pin function is digital Input, MCLR internally tied to VDD |
This corresponds to the CCS fuse settings for MCLR and NOMCLR.
Look at these Config bits for the Internal oscillator:
Quote: | bit 4, 1-0: FOSC<2:0>: Oscillator Selection bits (4)
101 = INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
100 = INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN |
These correspond to the fuse settings of INTRC and INTRC_IO. |
As i understand from here, there is no way to use ra5 as output. In the datasheet page 3, in peripheral functions it says there are 16 i/o pins. but there is not, so it is a lie. Am i correct?
Can it be used as receiver on rsr232? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19555
|
|
Posted: Mon Jun 05, 2017 8:23 am |
|
|
16 I/O pins, means 16 pins that can do some combination of input or output. Doesn't mean they can all do both input and output....
So, no, not a 'lie'. Just means you need to actually look at the data sheet and work out which pins can do what...
Also as soon as 'time' becomes involved, you need to have a clock statement. At present the chip will be selecting it's 'default' clock... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19555
|
|
Posted: Mon Jun 05, 2017 9:00 am |
|
|
There are various different ways of receiving asynchronous TTL serial (not technically 'RS232' - RS232 is a signalling standard using higher voltages, which the PIC can't actually handle - needs a buffer chip).
Hardware UART. Can only be done on the 'hardware' pins. RB1 & RB2 on your chip.
Simple software UART. Can be done on any PIC pin (with the same restrictions on 'direction' as for normal I/O), but 'receive', requires your code to be sitting 'listening' for the data to arrive.
Interrupt based software UART. The receive for this can only be done on pins that can trigger an interrupt.
Timer interrupt based software UART. Can again be done on any pin, but requires a 'tick' running at quite a high speed (I have posted a basic example in the code forum). |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Mon Jun 05, 2017 10:34 am |
|
|
Ttelmah wrote: | There are various different ways of receiving asynchronous TTL serial (not technically 'RS232' - RS232 is a signalling standard using higher voltages, which the PIC can't actually handle - needs a buffer chip).
Hardware UART. Can only be done on the 'hardware' pins. RB1 & RB2 on your chip.
Simple software UART. Can be done on any PIC pin (with the same restrictions on 'direction' as for normal I/O), but 'receive', requires your code to be sitting 'listening' for the data to arrive.
Interrupt based software UART. The receive for this can only be done on pins that can trigger an interrupt.
Timer interrupt based software UART. Can again be done on any pin, but requires a 'tick' running at quite a high speed (I have posted a basic example in the code forum). |
Thank you for your answers Ttelmah.
I thought i/o means both input and output. I found the way of datasheet a bit 'deceiving'. For example, if there was PIC with only 4 input and 8 output, writing 12 i/o on datasheet would not be the best way to explain the pinout in my opinion. I admit i wrote the lie part with frustration and a bit of rage. Next time, i will check the pinout on the picture and pay more attention to the arrows on pins.
About uart, i had meant the software uart. I assumed the input pin can be used as receive. I tried this and it worked. You mentioned about interrupts, is kbhit() function one of them? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19555
|
|
Posted: Mon Jun 05, 2017 11:07 am |
|
|
Problem is that to describe all the pin permutations on a PIC, even on quite simple ones, would cover several pages.
When you have pins that can be analog inputs, open collector outputs, logic inputs, logic outputs, and then in some cases inputs to particular peripherals, while only being outputs for for others, the simple description is never going to say it all.
As well as the tables of pins, the simple pin diagrams, have arrow heads printed on them for the directions supported. Some logic inputs even have different switching levels according to what peripheral is involved. This is why the data sheet has pages for this information....
This is also though why it is much easier to start with PICs with lots of pins, and only try to 'go smaller' once you know which pins you need. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|