I thought I would post this as it's a question we get a lot.
When the Assembly course was written the standard educational PICmicro was the PIC16F84.
The course was written with this device in mind.
Since then other PICs such as the 16F88 have become popular for educational use as they have additional features, such as Analogue inputs that give them more flexability.
A decision was taken to supply or new development boards with 16F88 devices.
Generally the courses can be used as they are for learning how to write Assembly.
However there are two important differences that need to be taken into account.
The 16F88 is set up so that the Analogue inputs are on by default. Unless you turn them off the Port A and Port B RB6 and RB7 pins will be analogue, and not available as digital outputs.
At the beginning you can just use the bit of code from the page β€Getting Started\Using E-blocks with the tutorialsβ€ as is.
e.g.
BSF 3, 5
CLRF H’9B’
BCF 3, 5
At the beginning you do not need to know what this code does, just that you need to add it to beginning of your code.
Later on, when you have become used to working with Assembly you will begin to understand what the code means, and how to rewrite it for added readability, which is what the second version does.
When you finally read about the Analogue ports the meaning of the code will become apparent and you will be able to modify the code if Analogue inputs are needed.
The second __Config issue is because the example files have embedded config words based on 16F84 configuration settings.
These settings were put there so that beginners could run the tutorials without worrying about how to configure the 16F84.
If a _Config is found in a file it takes presidence over the config as currently set up in the software.
This is useful for beginners who are unsure what XT and RC and Watchdogs etc. do.
However now that users may have a variety of devices, especially the 16F88, we have the problem that a config word suitable for the 16F84 may not be suitable for other devices.
So if you are using a 16F88 for instance you will need to comment out the _Config in the asm code.
You will need to understand and check the configuration settings now, something you did not need to do with the 16F84.
There is a section on the page giving examples and a brief description of the main settings to consider.
Please refer to this page for details.
Setting up ASM to use the PIC16F88 device.
-
- Posts: 3
- Joined: Mon Jan 02, 2006 5:42 am
- Location: Ventura, CA
'C', the HP488 and Analog Devices
You're right!
The online course goes for the 16F874, which is quite different than the 16F88 when it comes to Analog I/O.
Although I am a neophyte, I was able to figure it out by comparing the documentation for the 16F874 and the 16F88...
Here is my modification to the example code:
/* control registers for the A/D */
unsigned char ADCRESL@0x9e;
unsigned char ADCRESH@0x1e;
#define PORT_AN0 0x00
#define PORT_AN1 0x08
#define PORT_AN2 0x10
#define PORT_AN3 0x18
#define PORT_AN4 0x20
#define PORT_AN5 0x28
#define PORT_AN6 0x30
void setup_analog_hardware (char port)
{
port = port >> 2;
ansel = port; /* Setup ANALOG SELECT (ANSEL) */
adcon1 = 0x80; /* Right Justify, volt ref AVdd AVss */
trisa = port; /* Setup TRISA (Directional Control Bits) */
}
int read_adc0 ( unsigned char port ) /* return a 10 bit number in 16F88 */
{
unsigned char h, l;
int result ; /* must be an int because it could be 10 bits long */
/* enable the converter and start a conversion */
adcon0 = 0x85 | port;
/* spin while the conversion runs */
while ( adcon0 & 0x04 ) /* bit3 = is it done yet? (This is POLL MODE) */
;
/* can read the high nibble as it */
/* in bank 0 */
h = ADCRESH;
/* now need to flip to bank 1 to */
/* read the low byte. */
/* flip to the other bank */
asm bsf STATUS, RP0
/* load the byte into the W register */
asm movf _ADCRESL, W
/* flip back home */
asm bcf STATUS, RP0
/* store the W register in l */
asm movwf _l_read_adc0
result = (256 * h) + l;
return result;
}
Thanks for the good work!
The online course goes for the 16F874, which is quite different than the 16F88 when it comes to Analog I/O.
Although I am a neophyte, I was able to figure it out by comparing the documentation for the 16F874 and the 16F88...
Here is my modification to the example code:
/* control registers for the A/D */
unsigned char ADCRESL@0x9e;
unsigned char ADCRESH@0x1e;
#define PORT_AN0 0x00
#define PORT_AN1 0x08
#define PORT_AN2 0x10
#define PORT_AN3 0x18
#define PORT_AN4 0x20
#define PORT_AN5 0x28
#define PORT_AN6 0x30
void setup_analog_hardware (char port)
{
port = port >> 2;
ansel = port; /* Setup ANALOG SELECT (ANSEL) */
adcon1 = 0x80; /* Right Justify, volt ref AVdd AVss */
trisa = port; /* Setup TRISA (Directional Control Bits) */
}
int read_adc0 ( unsigned char port ) /* return a 10 bit number in 16F88 */
{
unsigned char h, l;
int result ; /* must be an int because it could be 10 bits long */
/* enable the converter and start a conversion */
adcon0 = 0x85 | port;
/* spin while the conversion runs */
while ( adcon0 & 0x04 ) /* bit3 = is it done yet? (This is POLL MODE) */
;
/* can read the high nibble as it */
/* in bank 0 */
h = ADCRESH;
/* now need to flip to bank 1 to */
/* read the low byte. */
/* flip to the other bank */
asm bsf STATUS, RP0
/* load the byte into the W register */
asm movf _ADCRESL, W
/* flip back home */
asm bcf STATUS, RP0
/* store the W register in l */
asm movwf _l_read_adc0
result = (256 * h) + l;
return result;
}
Thanks for the good work!
Bryan Allen
N6CPU
Ventura, CA
N6CPU
Ventura, CA
-
- Posts: 3
- Joined: Mon Sep 04, 2006 11:50 am
Re: Setting up ASM to use the PIC16F88 device.
Where is the page you are referring to please?
Ian wrote:I thought I would post this as it's a question we get a lot.
There is a section on the page giving examples and a brief description of the main settings to consider.
Please refer to this page for details.