16f628a Simple Program In C
Hi, I've started to learn programming mircocontrollers due to work school project. I started to learn basic from Nigel's page, yes it was a great introduction but only if I have more time. However due to work loads and co-operation with partners I need to fall back to C programming using mikroC (more structural and easy for others to understand). We've got simple mathematic functions done high low add minus blah. Now we Have arrive to the state to program the LCD controller. If just follow the mikroC C example and set it would probably be straight forward, but we don't want to make our project is copying people so we decide to to go for internal oscillation. Now the problem strike us is which device flag(configuration fuses) should be turned on.

According to nigel code it was _config0x3D18 which is 0011 1101 0001 1000(binary) so is this relfecting bit 13 flash mem protection off how ever bit 12 is undefined why 19 is 0? How To Use Input Type File In Jsf. Bit 8 CPD 1 code protection off bit 7 0 for VPP bit 6 0 reset disable bit5 0 digital input bit 4 1 (I don;t knwo here) ( i think this is where we set the clock for our lcd is external or internal bit 3 1 power up timer disable) Bit 2 wdt 0 (if we are making a real time clock this will be 1, right? Another function is need to prevent it loops without sopping right) oh besides this is example code from mikroC. Thanks for the reply guys, I re-read what I have written this morning. It was so incomprehensible, I should have told myself not to post while half asleep.
C Programming & Electronics Projects for $30 - $250. I need a code for a PIC IC 16F628A to: 1- Produce a PWM sine wave 60Hz oscillation for a DC/AC inverter. 2- Low voltage (10.5 DC) buzzer warning. You must give me both the source code and the HEX fil. Note that, Hi-Tech C is a bit difficult compared to MikroC as there is no built in functions. You can follow our. Files in large projects. Hence we are dealing with simple LED Blinking in this tutorial, ignore it and click Next. You should be familiar with following C Programming concepts. A number with a.
@BananaSongi yeah I have referred to the data sheet didn't understand how come a number binary 1,0 can represent 4 different clock state. @eng1 yeah I clicked the _INTRC_OSC_NOCLKOUT and other options but the LCD, only show boxes in the first line (electus LCD, uses Hitachi controller).I try and set the setting to default which is WDT off LVP off HSspeed oscilation ON _INTRC_OSC_NOCLKOUT ON, but the LCD is not showing the example code. Don't really know where have i gone wrong.
I made the connection correctly according to mikroC example HW configuration. My colleague got theirs work but they put the Vpp pin on high, (which is totally weird, since he uses mikroC standard library code and the LCD 4 bit module is only to deal with portB) I guess he is lying to me or it is a fluke, or he doesn't want to help since most of us couldn't get the LCD to work. Argh project due soon DIES..thanks in advance for the inputs. Things might be easier if started off as basic like everyone here stupid project communication and co-ordination mark.
Start Here with F628 PIC16F628 (2.6MB.pdf) for PIC16F628 Library of Routines or or Unzip. Updated 5/2/2009 The PIC16F628 is the starting point for PIC projects that require 6 to 15 'drive-lines.' (For 1 to 5 'drive-lines' use PIC12F629.) Obviously you shouldn't have a soldering iron so hot that it fumes the solder.
The PIC16F628 has 2k of program space for your program (2048 lines of code), operates at 4MHz and is cheaper than the PIC16F84A. The 4MHz oscillator is divided by 4 to get 1uS for each instruction. We use the type number: PIC16F628 to describe this microcontroller, but there are a number of part-numbers: PIC16F628 - Internal 4MHz or 37kHz operation, 18pin PDIP package (see photo below). PIC16F628A Internal 4MHz or 48kHz operation, plus low voltage programming, low speed clock mode, programmable BOR, on-chip voltage reference.
-I/P I indicates temperature range: I = -40°C to 85°C (normally 0°C to 70°C) P = PDIP package (see photo below).>E = -40°C to 125°C F = standard V DD range 3v to 5.5v LF = 2v to 5.5v SO is surface mount SS is surface mount -04 = 4MHz -20 = 20MHz A chip with -20 means the chip is capable of operating at 20MHz via an external crystal and will execute 5 instructions per second when the crystal is 20MHz. The chip has 4MHz and 37kHz internal oscillators. The chip advertised by R S Components () is PIC16F628-20/P. The PIC16F628A-20 I/P has 4MHz and 48kHz internal oscillators. A PIC16F628A microcontroller - 4MHz A 'drive-line' is an input/output line capable of driving up to 25mA. But this chip has one line that is input-only and this must be taken into account when designing a circuit.
The input-only line for PIC16F628 is RA5 - pin 4 and one line that is 'input and half-output' (RA4 - pin 3). (Other chips in the PIC range also have one line that is either input-only or can only produce a low-output - this applies to the PIC16F84. RA4 (pin 3) is an input pin but when used as an output, it will only sink 25mA. It will not source any current. And the PIC12F629 has GP3 (pin 4) as input only. We found RA4 of a PIC16F84 is a sinking-line only and this is not covered anywhere in any data sheet. To overcome this you need to add an emitter-follower transistor with a 2k2 to the positive and the line from the chip connected to the base.
See the circuit below. Port B is a 'full port' with 8 in-out lines but RB6 and RB7 are used for 'In-Circuit Programming' and these lines must be able to rise HIGH when the chip is programmed 'In-Circuit.' The PICkit-2 programmer does not have the full 25mA 'drive-capability' and thus the lines must be lightly loaded. If it is programmed 'out of circuit,' RB6 and RB7 can be used to sink and source 25mA as per any of the other lines. Port A has 6 in-out lines plus one input only line (RA5 - pin 4) and one 'input and half-output' (RA4 - pin 3). Thus the total is 14 plus one input and 'half-output' and one input-only.
The other two pins on the chip are for power (5v) and connection to 0v. The first thing to do is fit the microcontroller to an 18 pin socket so it can be easily taken in out of a project. Wipe the pins of the socket with hair-grease so it is easy to remove. Move the chip from one place to another with the socket attached. This makes it much easier to remove from the project and the programmer and prevents your fingers getting spiked. Make sure pin 1 on the chip aligns with the notch at the end of the socket.
You can also put a white dot over pin1 to to make identification easy. Fit the chip to a socket for easy handling Here is the pinout for the PIC16F628: The function of each pin For a full explanation of each pin, refer to PIC16F628 (2.6MB.pdf). G2 Drivers Test Checklist. Port A (RA) and Port B (RB) pins clearly identified Using a PIC in a circuit is very simple. Here is a circuit to drive a LED. All you have to do is create about 30 lines of code and the LED can be made to flash. Pre-written code is available as a.asm or as a.txt file Helpful information on how to write a program is available Simplest PIC16F628 circuit - the chip is sourcing UPGRADING FROM PIC16F84 TO PIC16F628 If you are upgrading from a PIC16F (or C) 84 (A), the pinout is below.
Note all the port pins are in the same positions on both chips. Port B is identical.
Port A on the PIC16F84 has 4 in/out and 1 'input and 'half-output'. The PIC16F628 has 6 in/out, one 'input and half-output' (RA4) and 1 input only (RA5). The thing you have to remember is: On both the PIC16F84 and PIC16F628, RA4 is an 'input and half-output'. When used as an output, these pins will only sink 25mA and source 0mA.
To make the pin source, connect the base of a transistor to the pin and put the transistor in emitter-follower mode by connecting the collector to the positive rail as in the diagram below. RA5 on a PIC16F628 is input only. MAKING RA4 SOURCE A CURRENT RA4 will not deliver a current to a load. To make it deliver a current, the following circuit can be used. Place a 2k2 on the base, to positive. When the pin is HIGH (or as an input) the emitter will source (deliver) 25mA (or more) as the base is being pulled HIGH by the 2k2.
The current via the emitter is equal to the base current multiplied by the gain of the transistor. When the output of the micro is LOW, the base will be pulled low by the pin and the emitter will be low. The circuit below will not allow for sinking a current. But it makes the pin source just like the other outputs. Don't forget, the maximum current for the chip, via all the pins is less than 250mA, to prevent overheating, so if you want to deliver a higher current, this type of buffer circuit can be used.
Making RA4 for 'F84 or 'F628 an output If you want to sink and source from RA4 for 'F84 or 'F628, one of the following circuits can be used: Making RA4 for 'F84 or 'F628 a HIGH/LOW output Circuit A has a HIGH of 4v and a LOW of about 1v and an output of about 100mA. Circuit B has a HIGH of about 5.4v and a LOW of about 0.6v and an output of about 250mA. Note: circuit B inverts the output pin of the chip. There is a point when circuit B actually creates a short across the power rail, when the output of the chip is changing from low-to-high or high-to-low, but this interval is so brief that the transistors and power rail will not be adversely affected. PIC16F84 Pinouts TWO 'IN-CIRCUIT PROGRAMMING' MODES The PIC16F628 chip can be programmed 'in-circuit' providing the programming pins are not used as output pins.
If they are used as output pins, the programmer will not have enough current to pull the pin high to produce a guaranteed clock or data pulse. However the pins can be lightly-loaded and the programmer will work. The PIC16F628 chip has 2 ways it can be programmed. It has Low-Voltage Programming and High-Voltage Programming. Both ways can be done 'In-Circuit.' The method we are using is called High-Voltage Programming as pin 4 receives a voltage slightly higher than 13.5v to activate the chip into programming mode.
To activate the Low-Voltage Programming method, the chip must be initially programmed via High-Voltage and the LVP bit set to '1' so that either Low-Voltage or High- Voltage Programming can be done 'in-Circuit.' In this state, Pin 10, RB5 cannot be used as in-out as it must receive a HIGH so the chip goes into LVP mode. In this case you lose an in-out pin and that's why we have not chosen this mode. We have chosen High-Voltage In-Circuit Programming mode. Here are the programming connections.
A separate programming board can be made to connect to the PICkit-2. We can call this board a PROGRAMMING BOARD as its only function is to program the chip. The board will look just like the circuit below. The chip is then removed and fitted to the project you are working on.
Alternatively the chip can be programmed while in the project you are currently designing if you include this socket and wiring. In-circuit Programming connections The programming socket on your project can be can be 5 pins as shown in the photo below and identified as Clock, Data, 0v, 5v and Vpp. The pins match the extension socket shown in the picture. The extension 'lead' consisting of a plug and socket fits into the 6 pins of the Microchip programmer PICkit-2 and brings out the 5 lines we need for In-Circuit Programming.
(we do not use the first line) The third photo/diagram below shows the Programming Socket on the circuit diagram above. You can see how the PICkit-2 programmer sits at the back of your project and the extension board fits over the 5 pins. If your project operates on 4.5v, turn the power OFF as this low voltage will upset the programmer. (from Microchip) Here are the details of the PICkit-2 programmer: This programmer is the cheapest and best for programming PIC chips and is available directly from Microchip for $50.00 plus postage. It comes with CD's and an extra PC board containing a PIC16F690 and components such as LEDs, a push button and a pot to get you started in programming. The programmer detects the type of chip being programmed and has features that help you to program the chip and avoid mistakes and faults.
It's a beautiful piece of equipment. It connects to the USB port on a lap-top. If you do not have access to a USB port, use the Multi Chip Programmer from Talking Electronics. Here is another. Price: USD $50.00 plus postage The PICkit 2 Starter Kit contains a PICkit 2 Microcontroller Programmer and a PICkit 2 Low Pin Count Demo Board containing a PIC16F690 PDIP for getting started with programming baseline and midrange flash microcontrollers. PICkit 2 takes advantage of Microchips Full-Speed USB device, thereby significantly speeding up development programming. The PICkit 2 Low Pin Count Demo Board supports 8-, 14-, and 20-pin PICmicros.
In addition to the PIC16F690, the board comes with 4 LEDs, a pushbutton, and a pot. Also included are 12 lessons to help get developers up to speed quickly on programming PICmicro MCUs. (purchase via Microchip Direct) Features of PICkit 2 Starter Kit.
• Low pin count demo board supporting 8/14/20-pin mid range PIC microcontrollers • 20-pin PIC16F690 Midrange microcontroller Note: Requires the AC162061 ICD Header and AC164110 adapter to debug. • A series of 12 Lessons on assembly programming that cover I/O, A/D converters, timers, interrupts, and data tables (All source code files are provided) • Getting Started in PICBASIC PRO tutorial on developing and debugging in BASIC with a FREE microEngineering Labs PICBASIC PRO™ Demo Compiler (contained on the PICkit-2 CD) • HI-TECH PICC™ LITE C Compiler on PICkit-2 CD. Microchip’s MPLAB IDE software for a complete code development environment The PICkit-2 comes with a lead to connect between the PICkit-2 and the USB port of your laptop but you will still need to build the extension plug-and-socket described above to fit between the PICkit-2 programmer and your project, so the PIC16F628 can be programmed. You will be able to program 'in circuit' if you put 5 pins on the project you are designing and connect to the programming socket on the PICkit-2 programmer. Or you can build a separate board called a PROGRAMMING BOARD and use the extension plug-and-socket. The 16F690 in the demo board is a complex chip and way-beyond the needs of a beginner. You still need to follow our instructions and build some of our simple projects if you want to start at the beginning of programming.
If you think you can come in on the 'third rung of the ladder' you are fooling yourself. You must do everything slowly and methodically if you don't want to get frustrated. You must start at the beginning. WHERE TO START: If you are converting a program from one micro to another (in the PIC family), here is a comparison chart. It shows the locations of the Special File Registers (from 000 to 06 or 1F). These include registers such as OPTION, TIMER, STATUS etc and the input/output port(s) 05 (RA) and 06 (RB).