PIC16F88 questions

Status
Not open for further replies.

Shake_ECET209

New Member
Hey guys, I am taking a microcontroller class. We are using PIC16F88 microcontrollers and PICkit 2, I think its CCS compiler. The program uses C code correct? I am having a fairly easy time writing the code, but I am having trouble actually wiring the microchip on the bread board. Are there any websites that show a diagram of what each port on the bread board means?? or how to connect a switch or LED?? The boards have LEDS, LCD, and switches on them, but there are plenty of slots and some labeled Vcc, Vdd. During my first project I could barley figure out how to bring power to the chip.

Thanks guys any info is greatly appreciated.
 
Vcc should be +5v and Vdd should be ground.

To wire a LED to the controller you will need a resistor in series with the LED.

Make sure your Vcc is not above 5.5 volts else you will damage the chip.

LCD's are a bit more complicated as you habe enable lines and you can have 4 or 8 wire mode.

Switches are fairly straight forward, I tend to use pull up or down resistors with a switch, all it does it detect the logic level at the chip.

Dont forget to pull MCLR high with a 10k resistor or similar.

I'm guessing you know some basics about digital electronics i.e. logic levels, and pull up / down resistors, OHMS law?

I would recommend a piece of free software called Electronics Assistant, it is available via a search on Google, and it is very useful for any electronics practitioner.

When you say compiler is MPLab, that isn't strictly true, MPLab is an IDE, Your compiler would be MPASM, or Hitech C (seeing as you are using a 16F).

Wilksey.
 
Pic16f88

Yeah, I have experience with Logic levels, and Ohms law. Not quite sure what you meant about pull up/down resistors*?

The bread boards we are using have the Vcc supply 5v. We have done a couple other labs using LCD's and Switches. Most of them are simple like setting a timer to count in binary on the LCD and adding a delay with a push bottom switch.

These are boards the TA put together so I am not 100% familiar with them yet.

MPlab is the Ide , I think the compiler is CCS? We use Pickit 2 to program the chip.

I am planning on making a digital clock that displays on two lines of the LCD screen. I want to add some random functions to it to show that I know how to use timers and delays and the basics.

Would that be possible? I need to get my idea approved by my prof. If this were taken I think a stopwatch would show that I can manipulate the basic functions that we've learned so far.
 
Wp100 you are right, my mistake, I didn't read it properly! I hadn't long got home from work

VDD and VCC are positve, VSS and VEE are ground.

CCS C?

Yeah, you could have a clock running, then press a switch and turn it into a stopwatch, with some other buttons / switches for set / reset.
Or if you wanted to be really snazzy you could have the first line displaying the clock and the second line displaying the stopwatch?

You could make it so when you press a button it puts a random pattern on a bank of LED's like a "Knight Rider" scrolling effect for example.

A Pull up / down resistor connects a pin to either +V(5v) or GND, pull down to ground, pull up to +V, some people use 10k, others use 4.7k etc, the value doesn't really matter, I always use 10k as I have hundreds of them! The function is to literally pull the voltage levels either way so not to "float", a PIC pin has 3 states (TRIState), input, output and high impedance (aka high z ), when reading an input you would connect one end of a switch to the pic pin and the other to say GND, but when the switch is open, the voltage to the input pin is floating, so it could "float" above or below logic high / low, which can cause undesirable effects (fast switching on and off of the pin) so what we do is when the switch is open pull the input the opposite direction, so a 10k up to +V would suit in your case.

You can turn the function off in software, a fuse setting called MCLR Enable, must be switched off / disabled.
 
Good Idea

Thanks for the info, These are some good ideas. I am thinking of displaying the Clock on one line of the LCD and then pressing a push button switch to display the clock in military time on the second line of the LCD.

I don't think the code will be very hard, I am not sure on the exact code to use for setting up a real time clock. I already know how to display the outputs on line 1 of the lcd and line 2 of the lcd.

Are there any C code tutorials on the type of function I would need to create a clock??
What is the statement gonna look like?
 
There are examples for C and PIC's, if you use CCS C your examples will be in:

C:\Program Files\PICC\Examples

There is also a folder here:

C:\Program Files\PICC\Drivers

In case you want to interface with any other peripherals, maybe a RTC?

Also, Microchip have some samples, specifically the PICDEM2 board has a clock function.

You would need buttons to initially set the clock, and then have maybe a timer interrupt every second to increment the second counter, and work with the minute / hour counter and update etc from that?
 
Hey guys, I got my project approved so I am going to be making a digital clock display on the second line of the LCD screen and when a push button is pressed I want it to display the That time in, Military time.

Would it be easy to add button a button to set the hours and another to set the minutes?? I don't want to mess with the am/pm options if it will over complicate the code.

I only want 1 button to take the Reg_timer and display it on the first line of the LCD in Military time, can that be done by a simple statement??

Am I going to need a 4th button to start the clock once it is set? And maybe use an interrupt so that anytime the 3rd button is pressed it will take whatever time is shown on the second line of the LCD screen and display it on the first line of the LCD screen in military time WITHOUT stopping the reg_timer from counting.

Any ideas on a simple setup with the least amount of switches?
 
If you are making a simple clock then you would not need any special IC's except maybe a voltage regulator. (LM7805) with a couple of 100nF caps either side of it to ground.
So you want 1 button to switch display information? Standard to Military, is this to be a toggle or a timeout, so for example, button is pressed, military time is displayed, 30 - 60 seconds later it will return to the standard time display format?

You will want 2 additional buttons, 1 for Hours, 1 for Minutes, and it's up to you if you wish to display seconds, and reset the second counter everytime the hour or minute button is released.

You do not need a start / stop button, you can if you wish, but going on the basis of when the unit is powered up, it will start from 00:00:00, you will then set the time, and once the keys are pressed (for hours / mins) the seconds counter will start from 0 and just work as a normal clock, until the power is lost again.

It depends on what you want to display on each line, if you want both times displaying then you can have the first button to display the military time on the 1st line of the LCD.
You can add the switch to RB0 / INT (Check datasheet, should be standard pin for interrupt) to get the interrupt if you wish.
 
Clock

Yeah, I want this clock to be as simple as possible. I want the button to toggle, Once the button is released the line of the LCD screen showing the military time will disappear. But I want the Other line of the LCD screen to constantly display the time && Not stop counting while the switch is pressed.

I don't want to display the seconds, I want the time to start counting as soon as the button to set the minutes is released.

When the system is powered up, I want to have the LCD screen display 00:00, Nothing on the second line. If I were to press the button to display military time at this point, I want 00:00 to appear on the second line. One I set the hours/minutes the counter will start. Nothing will show on the second line of the LCD screen until the button is pressed and held down, as soon as the button is released the military time will disappear.

I was trying to incorporate interrupts in the code, because it is something we learned in class. The only issue is that I don't want the clock to stop counting when the button is pressed to display the military time.
 
Last edited:
You can use the timer interrupt to count the seconds, but to count reliably you should continue to use polling of the buttons.

I am not sure how multiple interrupts would affect the timer interrupt. It is something you would have to try.
 
Source code

hey guys I found some source code that is similar to what I am trying to do.
This project uses the PIC16f88 but is this code in "C" ?? looks like C++?



Code:
Device = 16F88
@CONFIG_REQ
@__CONFIG _CONFIG1, INTRC_IO & PWRTE_ON & MCLR_ON & BODEN_OFF & LVP_OFF & WRT_PROTECT_OFF & CPD_OFF & DEBUG_OFF & WDT_OFF & CCP1_RB0 & FCMEN_OFF & IESO_OFF

OSCCON = OSCCON | %01100000
OSCCON = OSCCON & %11101100
CMCON = 0                                    
TRISA = %11100000
TRISB = %00001111
ALL_DIGITAL = TRUE
PORTB_PULLUPS = TRUE
Dim SS,MM,HH,DY,MO,YR,CH,BCD As Byte
SS = 0 : MM = 0 : HH = 0 : DY = 0 : MO = 0 : YR = 0
Declare LCD_DTPIN PORTB.4   'Sets up the high 4 bits of PortB as the data pins for the LCD
Low PORTA.3
Declare LCD_ENPIN PORTA.4   'Defines Port A Bit 4 as the LCD's Enable pin
Declare LCD_RSPIN PORTA.2   'Defines Port A Bit 2 as the LCD's RS pin
Declare LCD_INTERFACE 4     'Specify that we are talking to the LCD in 4 bit mode
Declare LCD_LINES 2 
Declare SLOW_BUS TRUE
BStart
BusIn %11010001,00,[CH]
BStop
If CH > $7F Then CH = CH - $80
BStart
BusOut %11010001,00,[CH]
BStop
Cls
Print At 1,1,"  LCD Clock"
Print At 2,1,"V1.2 by VK2TIM"
DelayMS 5000
Cls
getrtc: 
     BStart
     BusIn %11010001,00,[SS]
     BusIn %11010001,01,[MM]
     BusIn %11010001,02,[HH]
     BusIn %11010001,04,[DY]
     BusIn %11010001,05,[MO]
     BusIn %11010001,06,[YR]
     BStop
Cursor 1,1
GoSub showtime
Cursor 2,1
GoSub showdate
     GoSub delay
     GoSub keyscan
     GoTo getrtc
sec:
SS = $00                                      
    GoSub wrtdata
    Cls
    Print At 1 , 1 , "Reset seconds "   'Text for instructional value only
    Cursor 2,1
    GoSub showtime
    GoSub delay
    GoSub keyscan
    Cls
    GoTo getrtc
mn:
BCD = $00
MM = MM + 1 
BCD = MM & $0F
If MM > $59 Then 
MM = 0
ElseIf BCD = $0A Then
MM = MM + $06
EndIf    
    GoSub wrtdata
    Cls
    Print At 1 , 1 , "Setting Minutes "   'Text for instructional value only
    Cursor 2,1
    GoSub showtime     'Jump to routine to show the time in HH:MM:SS
    GoSub delay
    GoSub keyscan      'Check for buttonpress
    Cls
    GoTo getrtc
hr:
BCD = $00
HH = HH + 1                                      
BCD = HH & $0F
If HH > $23 Then 
HH = 0                                
ElseIf BCD = $0A Then 
HH = HH + $06
EndIf  
    GoSub wrtdata
    Cls
    Print At 1 , 1 , "Setting Hours     "   'Text for instructional value only
    Cursor 2,1
    GoSub showtime    'Prints the time in HH:MM:SS
    GoSub delay
    GoSub keyscan
    Cls
    GoTo getrtc
day:
BCD = $00
DY = DY + 1                                      
BCD = DY & $0F
    If BCD = $0A Then 
    DY = DY + $06
    EndIf
    If MO = $09 Then
     GoSub thirty
    ElseIf MO = $04 Then
     GoSub thirty
    ElseIf MO = $06 Then
     GoSub thirty
    ElseIf MO = $11 Then
     GoSub thirty
    ElseIf MO = $02 Then GoSub twentynine
    Else
     GoSub thirtyone
    EndIf
   GoSub wrtdata
    Cls
    Print At 1 , 1 , "Setting Day     "   'Text for instructional value only
    Cursor 2,1
    GoSub showdate
    GoSub delay
    GoSub keyscan
    Cls
    GoTo getrtc
mnth:
BCD = $00
MO = MO + 1                                                                      
BCD = MO & $0F
If MO > $12 Then 
MO = $01
ElseIf BCD = $0A Then 
MO = MO + $06   
EndIf    
    GoSub wrtdata
    Cls
    Print At 1 , 1 , "Setting Month     "   'Text for instructional value only
    Cursor 2,1
    GoSub showdate
    GoSub delay
    GoSub keyscan
    Cls
    GoTo getrtc
year:
BCD = $00
YR = YR + 1                                      
BCD = YR & $0F
If YR > $99 Then 
YR = $00
ElseIf BCD = $0A Then 
YR = YR + $06   
EndIf
    GoSub wrtdata
    Cls
    Print At 1 , 1 , "Setting Year     "   'Text for instructional value only
    Cursor 2,1
    GoSub showdate
    GoSub delay
    GoSub keyscan
    Cls
    GoTo getrtc
wrtdata:
BStart
     BusOut %11010000,00,[SS]
     BusOut %11010000,01,[MM]
     BusOut %11010000,02,[HH]
     BusOut %11010000,04,[DY]
     BusOut %11010000,05,[MO]
     BusOut %11010000,06,[YR]
     BStop
Return
thirty:
If DY > $30 Then DY = $01
Return
thirtyone:
If DY > $31 Then DY = $01
Return
twentynine:
If DY > $29 Then DY = $01
Return
showdate:
If YR < 10 Then
Print "Date ", HEX DY ,"/", HEX MO ,"/200", HEX YR, "  "
Else
Print "Date ", HEX DY ,"/", HEX MO ,"/20", HEX YR, "  "
EndIf
Return
showtime:
If SS<10 And MM<10 Then 
Print "Time ", HEX HH ,":0",HEX MM ,":0",HEX SS ," "
ElseIf SS<10 Then 
Print "Time ", HEX HH ,":",HEX MM ,":0",HEX SS ," "
ElseIf MM<10 Then 
Print "Time ", HEX HH ,":0",HEX MM ,":",HEX SS ," "
Else
Print "Time ", HEX HH ,":",HEX MM ,":",HEX SS ," "  'Print date and time, and add leading zero's where needed
EndIf
Return
keyscan:
    If PORTB.0 = 0 And PORTB.3 = 1 Then GoTo sec    'If PortB Bit 0 is pulled low, jump to routine to set the seconds to 0
    If PORTB.1 = 0 And PORTB.3 = 1 Then GoTo mn     'If PortB Bit 1 is pulled low, jump to routine to increment Minutes
    If PORTB.2 = 0 And PORTB.3 = 1 Then GoTo hr     'If PortB Bit 2 is pulled low, jump To routine To increment Minutes
    If PORTB.0 = 0 And PORTB.3 = 0 Then GoTo day    'If PortB Bit 3 is pulled low, and PortB Bit 0 is pulled low, set the day 
    If PORTB.1 = 0 And PORTB.3 = 0 Then GoTo mnth   'If PortB Bit 3 is pulled low, and PortB Bit 1 is pulled low, set the month 
    If PORTB.2 = 0 And PORTB.3 = 0 Then GoTo year   'If PortB Bit 3 is pulled low, and PortB Bit 2 is pulled low, set the year
Return
delay:
DelayMS 500
Return
 
Yeah I was looking for some CCS C code for a RTC that I could modify but I think I am just going to start from scratch.
Seems like there is going to be quite a bit of "For" loops.
 
Yeah but in class we are using CCS "C" code. Its a project and we have to explain what we wrote or ad least show that we understand the code. I would be the only person in class using a different code, don't think it would go over to good with the teacher.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…