Showing posts with label MICROCONTROLLER. Show all posts
Showing posts with label MICROCONTROLLER. Show all posts

Wednesday, February 24

Digital Camera Interface


How to interface CMOS camera and microcontroller? well, Iñaki Navarro Oiza had made great microcontroller project about it. The camera called c3088 uses a CMOS image sensor OV6620 from Omnivision. To communicate between microcontroller and camera he use I2C protocol. As processor it used Atmel AVR ATmega16.


"The aim of this project is the development and construction of an interface between a CMOS camera and a computer. This interface allows a user to get images from the camera, to change some of the properties of the camera as brightness, luminance, etc from a computer. Also some image process is implemented allowing the camera to track white objects and follow them with a servomotor. The interface was implemented using the Atmel AVR ATmega16 microcontroller."


Download code, schematic, slide and documentation click here

Card Reader Using Microcontroller


This is a simple version of Card Reader. Why? because this Magnetic Card Reader only in read only environment. It only read the information stored in magnetic card. The purpose of the project is used as card debugger. There are three main part in this project :


A reader to capture digital characters from the card
A RISC microcontroller to store data and check for errors
A display to relay the magstripe contents to the viewer


As processor it use microcontroller AVR ATtiny 2313. For Reader it uses Panasonic ZU-M2121S451 Reader. and for display use LCD 16x2.

"The Magstripe (Track 2) Reader project can be used to view numerics stored a magnetic data card. Although there is no writeback ability, the device is very useful as a card debugger. The treatise will use an LCD character display to relay this data to the user. The circuit uses an AVR microcontroller and can modified to work with similar RISC controllers."
Although the card reader can't write back to magnetic card, I guess this is a one of good reference to learn how card reader work. For download the reference clik here (zip file)

Thursday, January 21

A Simple Clock using DS1307 + PIC16F877A



A Simple Clock using DS1307 + PIC16F877A
Even I have posted about "DS1307 + PIC16F877A", I didn't have chance to make a real prototype of the clock. I have done only on the simulation software. Today, I have received a comment about that post. ah_bear followed my code and schematic on that post but the clock didn't work. This is because the code on that post is for reading time from DS1307 so there must be some values in the DS1307 before you can read. The solution is simple. Just place setting time codes before reading codes
The schematic of the clock is very simple. Please note that the schematic does not show power supply to the PIC16F877A and the DS1307, you have to connect them by youself. If you are new to PIC/LCD interface please see MikroC "Hello World!" LCD example .


The source code:

//Sample code for
//DS1307 RTC Interfacing with PIC16F877A
//Coded by punkky@gmail.com
//Compiler: mikroC 8.0.0
//http://picnote.blogspot.com
//05/01/2009
//Use with your own risk

unsigned short read_ds1307(unsigned short address );
void write_ds1307(unsigned short address,unsigned short w_data);
unsigned short sec;
unsigned short minute;
unsigned short hour;
unsigned short day;
unsigned short date;
unsigned short month;
unsigned short year;
unsigned short data;
char time[9];
char ddate[11];

unsigned char BCD2UpperCh(unsigned char bcd);
unsigned char BCD2LowerCh(unsigned char bcd);

void main(){

I2C_Init(100000); //DS1307 I2C is running at 100KHz
PORTB = 0;
TRISB = 0; // Configure PORTB as output
TRISC = 0xFF;
Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, "TIME:");
Lcd_Out(2, 1, "DATE:");

//Set Time
write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
write_ds1307(1,0x10); //write min 27
write_ds1307(2,0x01); //write hour 14
write_ds1307(3,0x02); //write day of week 2:Monday
write_ds1307(4,0x05); // write date 17
write_ds1307(5,0x01); // write month 6 June
write_ds1307(6,0x09); // write year 8 --> 2008
write_ds1307(7,0x10); //SQWE output at 1 Hz
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator

while(1)
{
sec=read_ds1307(0); // read second
minute=read_ds1307(1); // read minute
hour=read_ds1307(2); // read hour
day=read_ds1307(3); // read day
date=read_ds1307(4); // read date
month=read_ds1307(5); // read month
year=read_ds1307(6); // read year

time[0] = BCD2UpperCh(hour);
time[1] = BCD2LowerCh(hour);
time[2] = ':';
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[5] = ':';
time[6] = BCD2UpperCh(sec);
time[7] = BCD2LowerCh(sec);
time[8] = '\0';

ddate[0] = BCD2UpperCh(date);
ddate[1] = BCD2LowerCh(date);
ddate[2] ='/';
ddate[3] = BCD2UpperCh(month);
ddate[4] = BCD2LowerCh(month);
ddate[5] ='/';
ddate[6] = '2';
ddate[7] = '0';
ddate[8] = BCD2UpperCh(year);
ddate[9] = BCD2LowerCh(year);
ddate[10] = '\0';

Lcd_Out(1,6,time);
Lcd_Out(2,6,ddate);
Delay_ms(50);
}
}

unsigned short read_ds1307(unsigned short address)
{
I2C_Start();
I2C_Wr(0xd0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(address);
I2C_Repeated_Start();
I2C_Wr(0xd1); //0x68 followed by 1 --> 0xD1
data=I2C_Rd(0);
I2C_Stop();
return(data);
}

unsigned char BCD2UpperCh(unsigned char bcd)
{
return ((bcd >> 4) + '0');
}

unsigned char BCD2LowerCh(unsigned char bcd)
{
return ((bcd & 0x0F) + '0');
}
void write_ds1307(unsigned short address,unsigned short w_data)
{
I2C_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(0xD0); // send byte via I2C (device address + W)
I2C_Wr(address); // send byte (address of DS1307 location)
I2C_Wr(w_data); // send data (data to be written)
I2C_Stop(); // issue I2C stop signal
}


Posted by punkky at Monday, January 05, 2009
Topics: Clock, DS1307, Microcontroller, PIC16F877a, Schematic, Source Code
12 comments:
Blue Tear's said...
Great post. But i need help to increase buttons to set time and date. Can you help me with this.

January 6, 2009 10:20 PM
punkky said...
I'm working on the complete clock. I will post the whole things. Please come back later.

January 11, 2009 10:49 AM
Blue Tear's said...
Can you post your new code for the buttons. Thanks

January 15, 2009 8:28 PM
oxoxo said...
thanks for sharing the code.
but i do not understand the datasheet for DS1307 on how to set the time that i want..for example, i want to set the time for 24-hr clock at 0800 or 1900(7p.m). i don get to understand how u write 0x01 as 14 hour (write_ds1307(2,0x01); //write hour 14) and other timing as well.
do advise this asap, a million thanks~!

March 25, 2009 12:33 AM
PIC said...
good program

April 25, 2009 6:53 PM
trungnt said...
Based on your code, I have written code for RTC using buttons to set time and 12 Led 7-Seg to show time (year-month-date-hour-min-sec). Thanks!!!

May 27, 2009 9:53 PM
Chuck said...
Can you help me? This is my first attempt to program a chip.
What to make a red clock for car.
I've been trying to program a pic chip 16f628A for the last month.
For some reason all I get is ERROR hardware not found on COM.
I have down loaded picaxe programming editor.
I purchased the pic programmer.
I have a USB to serial cable.
What is wrong?????

July 14, 2009 4:54 PM
Chuck said...
Me again. You can contact me at sbcm07@hotmail.com

July 15, 2009 3:26 AM
Ranier said...
hi everyone, help me to make add-ons to this circuit.. i will make an alarm clock that will based to the digital clock made... this is my first time to program to a chip. pls help me... here's my email address... ranier21ph@yahoo.com

October 6, 2009 5:32 PM
KENNY said...
may i know wat type of crystal r using?

December 8, 2009 8:16 PM
sarah said...
may i know which software did you used to simulate the circuit and the coding.tq

December 10, 2009 11:22 PM
Minos said...
I've made the schematic, but the simul inisis doesn't work. time is 00:00:00, and date 00:00:2000. can u help me pls?

January 11, 2010 7:58 PM
Post a Comment

Links to this post
Create a Link

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)


The source code:

//Sample code for
//DS1307 RTC Interfacing with PIC16F877A
//Coded by punkky@gmail.com
//Compiler: mikroC 8.0.0
//http://picnote.blogspot.com
//05/01/2009
//Use with your own risk

unsigned short read_ds1307(unsigned short address );
void write_ds1307(unsigned short address,unsigned short w_data);
unsigned short sec;
unsigned short minute;
unsigned short hour;
unsigned short day;
unsigned short date;
unsigned short month;
unsigned short year;
unsigned short data;
char time[9];
char ddate[11];

unsigned char BCD2UpperCh(unsigned char bcd);
unsigned char BCD2LowerCh(unsigned char bcd);

void main(){

I2C_Init(100000); //DS1307 I2C is running at 100KHz
PORTB = 0;
TRISB = 0; // Configure PORTB as output
TRISC = 0xFF;
Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, "TIME:");
Lcd_Out(2, 1, "DATE:");

//Set Time
write_ds1307(0,0x80); //Reset second to 0 sec. and stop Oscillator
write_ds1307(1,0x10); //write min 27
write_ds1307(2,0x01); //write hour 14
write_ds1307(3,0x02); //write day of week 2:Monday
write_ds1307(4,0x05); // write date 17
write_ds1307(5,0x01); // write month 6 June
write_ds1307(6,0x09); // write year 8 --> 2008
write_ds1307(7,0x10); //SQWE output at 1 Hz
write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator

while(1)
{
sec=read_ds1307(0); // read second
minute=read_ds1307(1); // read minute
hour=read_ds1307(2); // read hour
day=read_ds1307(3); // read day
date=read_ds1307(4); // read date
month=read_ds1307(5); // read month
year=read_ds1307(6); // read year

time[0] = BCD2UpperCh(hour);
time[1] = BCD2LowerCh(hour);
time[2] = ':';
time[3] = BCD2UpperCh(minute);
time[4] = BCD2LowerCh(minute);
time[5] = ':';
time[6] = BCD2UpperCh(sec);
time[7] = BCD2LowerCh(sec);
time[8] = '\0';

ddate[0] = BCD2UpperCh(date);
ddate[1] = BCD2LowerCh(date);
ddate[2] ='/';
ddate[3] = BCD2UpperCh(month);
ddate[4] = BCD2LowerCh(month);
ddate[5] ='/';
ddate[6] = '2';
ddate[7] = '0';
ddate[8] = BCD2UpperCh(year);
ddate[9] = BCD2LowerCh(year);
ddate[10] = '\0';

Lcd_Out(1,6,time);
Lcd_Out(2,6,ddate);
Delay_ms(50);
}
}

unsigned short read_ds1307(unsigned short address)
{
I2C_Start();
I2C_Wr(0xd0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(address);
I2C_Repeated_Start();
I2C_Wr(0xd1); //0x68 followed by 1 --> 0xD1
data=I2C_Rd(0);
I2C_Stop();
return(data);
}

unsigned char BCD2UpperCh(unsigned char bcd)
{
return ((bcd >> 4) + '0');
}

unsigned char BCD2LowerCh(unsigned char bcd)
{
return ((bcd & 0x0F) + '0');
}
void write_ds1307(unsigned short address,unsigned short w_data)
{
I2C_Start(); // issue I2C start signal
//address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
I2C_Wr(0xD0); // send byte via I2C (device address + W)
I2C_Wr(address); // send byte (address of DS1307 location)
I2C_Wr(w_data); // send data (data to be written)
I2C_Stop(); // issue I2C stop signal
}

1Hz Clock Generator using PIC12F675


1Hz Clock Generator using PIC12F675
Based on the idea from http://www.josepino.com/pic_projects/?timebaseI have created a 1Hz Clock Generator. I use PIC12F675 as it's available locally. Its price is just about US$1.
The concept is using 32.768kHz crystal as a clock for the PIC. Therefor, the internal instruction clock is 32768/4 = 8192 Hz. By using the 16 bit Timer1 to count the instruction clock cycles, the interrupt will occur every 8 second. This period can be reduced by setting initial value of the Timer1 (TMR1H:TMR1L). I have to make Timer1 to count up to 8192 for generating overflow interrupt every 1 second. To make Timer1 count up to 8192, the initial value of TMR1 must be 65536-8192 = 57344 or 0xE000. This means TMR1H = 0xE0 and TMR1L = 0x00. In this case, I need to set only the TMR1H=0xE0 and let TMR1L runs continuously. By changing the initial value of Timer1, I can generate almost any frequencies.

An application for this project is a precise 1Hz blinking LED signal :) ha ha. I know that it's not useful but I think it's fun to look at (am I crazy?). Another application is a precise 1Hz time base for a clock.

The source code is written in MikroC.

// PIC12F675
// 1Hz Time Base Osc.
// Timer1 Module
// 32.768 KHz
unsigned short tick;
void Init ();
void interrupt ()
{
if (PIR1.TMR1IF)
{
TMR1H = 0xE0;
PIR1.TMR1IF = 0;
tick = 1;
}
}
void main ()
{
tick = 0;
//Initialize Ports and Timer1 Module
Init ();
while (1)
{
if (tick)
{
tick = 0;
GPIO = (1 <<> 0xF0)
{
GPIO = 0;
}
}
}
void Init ()
{
TRISIO = 0;
//Make all pins as output ports
GPIO = 0;
//Use Timer1 module
INTCON.GIE = 1;
INTCON.PEIE = 1;
T1CON = 0x01;
//Overflow every 8192
TMR1H = 0xE0;
TMR1L = 0x00;
// Enable TMR1 interrupt
PIE1.TMR1IE = 1;
}





Saturday, December 12

PROGRAMMING AND CUSTOMIZING THE AVR MICROCONTROLLER

PROGRAMMING AND CUSTOMIZING THE AVR MICROCONTROLLER



PIC Microcontroller Project Book

PIC Microcontroller Project Book


Programming PIC Microcontroller in BASIC

Programming PIC Microcontroller in BASIC


Introduction to Microprocessors and Microcontroller

Introduction to Microprocessors and Microcontroller



C Programming for Microcontroller

C Programming for Microcontroller



The 8051 Microcontroller & Embedded Systems

The 8051 Microcontroller & Embedded Systems



8051 Microcontroller Architecture, Programming and Applications

8051 Microcontroller Architecture, Programming and Applications


8051_Microcontroller

8051_Microcontroller


The 8051 Microcontroller 2nd Edition 1995

The 8051 Microcontroller 2nd Edition 1995


PIC Microcontrollers

PIC Microcontrollers


PIC Microcontrollers

PIC Microcontrollers



Programming and Customizing the PIC Microcontroller

Programming and Customizing the PIC Microcontroller


BASIC for PIC microcontrollers

BASIC for PIC microcontrollers


the PIC Microcontroller with MBASIC

the PIC Microcontroller with MBASIC