i am romuald ,and i am kinda new when it comes to pic programming ..
humm, actually i a writing here , to require your help for a program i have written . actually the program is a 0-15 counter using timer interrupt and TMR0 . i want the system to count from 0 to 15 seconds ..
For this i use a pic16f877a , at 20MHz
but for the program i am using the internal frequency of 4MHz
here below is the program , i have written . it compiles successful , but when i go for simulation at Pic simulator or Proteus . i have nothing .. and i am sure my simulation software work properly because ,i had already used them for other pic project successfully .
i am afraid i am missing something in my programs
code :
- CODE: SELECT_ALL_CODE
#include<pic.h>
__CONFIG (0x3F32);
#define lcd PORTC
#define rs RB4
#define e RB5
unsigned char int_counter = 0;
unsigned char counter = 0;
unsigned char data ;
// =============================Prototypes===========================
//===================================================================
void lcd_goto(unsigned char data);
void send_config(unsigned char data);
void send_char(unsigned char data);
void e_pulse(void);
void lcd_clr(void);
void send_string(const char *s);
void dis_num(unsigned long data);
void delay(unsigned long data);
//=====================================================================
//=====================================================================
void main()
{
ADCON1=0b00000110;
TRISA=0b11111111;
TRISB=0b00000000;
TRISC=0b00000000;
PORTA =0;
PORTB=0;
OPTION_REG = 0b00000111;
INTCON = 0b10100000;
TMR0=0x00;
while(1)
{
PORTC=0;
PORTD=0;
send_config(0b00001001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function
// void interrupt()
//{
if (INTCON == 0b10100100)
{ int_counter++;
if(int_counter==61)
{ counter ++;
lcd_clr();
lcd_goto(0);
send_string(" Confirm ?");
delay(5000);
lcd_goto(23);
dis_num( counter);
int_counter = 0 ;
delay(5000);
}
}
INTCON = 0b10100000;
// }
}
}
//========================================================================================
// LCD functions
//========================================================================================
void send_config(unsigned char data)
{
rs=0; //clear rs into config mode
lcd = data;
delay(10);// before 50000
e_pulse();
}
void send_char(unsigned char data)
{
rs=1; //set rs into write mode
lcd =data;
delay(50);// before 50000
e_pulse();
}
void e_pulse(void)
{
e=1;
delay(10);
e=0;
delay(10);
}
void lcd_goto(unsigned char data)
{
if(data<16)
{
send_config(0x80+data);
}
else
{
data=data-20;
send_config(0xc0+data);
}
}
void lcd_clr(void)
{
send_config(0x01);
delay(600);
}
void send_string(const char *s)
{
//unsigned char i=0; ( the comments bars weren't ther before .
while (s && *s)send_char (*s++);
}
void dis_num(unsigned long data)
{
unsigned char hundred_thousand;
unsigned char ten_thousand;
unsigned char thousand;
unsigned char hundred;
unsigned char tenth;
hundred_thousand = data/100000;
data = data % 100000;
ten_thousand = data/10000;
data = data % 10000;
thousand = data / 1000;
data = data % 1000;
hundred = data / 100;
data = data % 100;
tenth = data / 10;
data = data % 10;
if(hundred_thousand>0)
{
send_char(hundred_thousand + 0x30); //0x30 added to become ASCII code
send_char(ten_thousand + 0x30);
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(ten_thousand>0)
{
send_char(ten_thousand + 0x30); //0x30 added to become ASCII code
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(thousand>0)
{
send_char(thousand + 0x30); //0x30 added to become ASCII code
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(hundred>0)
{
send_char(hundred + 0x30); //0x30 added to become ASCII code
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(tenth>0)
{
send_char(tenth + 0x30); //0x30 added to become ASCII code
send_char(data + 0x30);
}
else send_char(data + 0x30); //0x30 added to become ASCII code
}
//===============================================================================================
// General Purpose function
//===============================================================================================
void delay(unsigned long data)
{
for( ;data>0;data-=1);
}