Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Sort By

USER REQUESTS

first | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 last
marek stručovský
mlike

posted on 2012/11/02 04:47:00 PM CET

Timers (Real time clock)

Help with 16F877A and DS1302

Hello.
Could someone help me with DS1302 and 16F877A? I programm in microbasic pro for pic ver. 5.4. My programm has two parts. First part is for 18b20 and it works fine, second part is for DS1302 but it part doesnt work. Could someone send me some advice?

program topenipokus
'
' rclk = ra1 DS1302
' io = ra2
' rst = RA3

dim LCD_RS as sbit at Re0_bit
LCD_EN as sbit at Re2_bit
LCD_D4 as sbit at Rd4_bit
LCD_D5 as sbit at Rd5_bit
LCD_D6 as sbit at Rd6_bit
LCD_D7 as sbit at Rd7_bit
LCD_RS_Direction as sbit at TRISe0_bit
LCD_EN_Direction as sbit at TRISe2_bit
LCD_D4_Direction as sbit at TRISd4_bit
LCD_D5_Direction as sbit at TRISd5_bit
LCD_D6_Direction as sbit at TRISd6_bit
LCD_D7_Direction as sbit at TRISd7_bit

' End Lcd module connections

const TEMP_RESOLUTION as byte = 12

dim text as char[5]
text1 as char[5]
temp, pomocny_cas as word
i,j,k, dummy1, tempa, pokus,mesice,
vteriny, minuty, hodiny,rok, dny as byte
cas as byte

sub procedure Display_Temperature( dim temp2write as word )
const RES_SHIFT = TEMP_RESOLUTION - 8

dim temp_whole as byte
temp_fraction as byte
text = "000.0"
' Check if temperature is negative
if (temp2write and 0x8000) then
text[0] = "-"
temp2write = not temp2write + 1
end if

' Extract temp_whole
temp_whole = word(temp2write >> RES_SHIFT)
' Convert temp_whole to characters
if ( temp_whole div 100 ) then
text[0] = temp_whole div 100 + 48
else
text[0] = " "
end if

text[1] = (temp_whole div 10)mod 10 + 48 ' Extract tens digit
text[2] = temp_whole mod 10 + 48 ' Extract ones digit

temp_fraction = word(temp2write) and 0x0f ' extract 0,5 stupne
if (temp_fraction >= 8) then
text[4] = 53
else text[4] = 48
end if
' Print temperature on Lcd
Lcd_Out(1, 6, text)
end sub


sub procedure cteni_casu
porta = 0
trisa = 0
clearbit(porta,1)
clearbit(porta,2)
setbit(porta,3)

for i = 0 to 7 'send command byte, k is variable of register which I want read
clearbit(porta,1) ' clk of DS1302
if testbit(k,0) = 1 then
setbit(porta,2)
else clearbit(porta,2)
end if
k = k >>1
delay_us(10)
setbit(porta,1)
clearbit(porta,2) ' end of clock
delay_us(10)
next i

clearbit(porta,2)
setbit(trisa,2) ' switch (porta,2) from output to input (is it right?)

for i = 0 to 7
if testbit(porta,2) = 1 then ' store value from (porta,2) into register cas
setbit(cas,7)
else clearbit(cas,7)
end if
setbit(porta,1)
delay_us(10)
clearbit(porta,1)
delay_us(10)
cas =cas >>1
next i
trisa = 0
porta = 0 'end of transfer
end sub

sub procedure nastaveni_casu 'set register
trisa = 0
clearbit(porta,1)
clearbit(porta,2)
setbit(porta,3)
for i = 0 to 15
if testbit(pomocny_cas,0) = 1 then
setbit(porta,2)
else clearbit(porta,2)
end if
delay_us(1)
setbit(porta,1)
delay_us(1)
clearbit(porta,1)
pomocny_cas = pomocny_cas >>1
next i
porta = 0
end sub

sub procedure transform_cas
vteriny = ((vteriny and 0xF0) >>4)*10 + (vteriny and 0xF0)
minuty = ((minuty and 0xF0) >>4)*10 + (minuty and 0xF0)
hodiny = ((hodiny and 0xF0) >>4)*10 + (hodiny and 0xF0)
rok = (dny and 0xC0) >>6
dny = ((dny and 0x30) >>4)*10 + (dny and 0x0F)
mesice = ((mesice and 0x10) >>4)*10 + (mesice and 0x0F)
end sub

sub procedure zobraz_cas
lcd_chr(2,16,(vteriny mod 10) +48)
lcd_chr(2,15,(vteriny / 10) + 48)
lcd_chr(2,14,".")
lcd_chr(2,13,(minuty mod 10) +48)
lcd_chr(2,12,(minuty / 10) + 48)
lcd_chr(2,11,":")
lcd_chr(2,10,(hodiny mod 10) +48)
lcd_chr(2,9,(hodiny /10) +48)
end sub


main:
porta = 0
adcon1 =6
cmcon =7
trisa = 0

text = "000.0"
i = 0
j = 0
k = 0

Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear Lcd
Lcd_Cmd(_LCD_CURSOR_OFF) ' Turn cursor off
Lcd_Out(1, 1, "Temp:")
Lcd_chr(1,11,223) ' Print degree character, "C" for Centigrades
Lcd_Chr(1,12,"C") ' If you see greek alpha letter try typing 178 instead of 223



bytetostr(dummy1,text1)
lcd_out(2,1,text1)

pomocny_cas = 0x008E 'set control register- write is on
nastaveni_casu()
delay_ms(1)
pomocny_cas = 0x0082 'set second register- 7th bit is 0 - clock is enable
nastaveni_casu()
delay_ms(1)
pomocny_cas = 0x808E 'set control register - read is enable
nastaveni_casu()


while (TRUE)
'--- Perform temperature reading
Ow_Reset(PORTb, 5) ' Onewire reset signal
Ow_Write(PORTb, 5, 0xCC) ' Issue command SKIP_ROM
Ow_Write(PORTb, 5, 0x44) ' Issue command CONVERT_T
Delay_us(120)

Ow_Reset(PORTb, 5)
Ow_Write(PORTb, 5, 0xCC) ' Issue command SKIP_ROM
Ow_Write(PORTb, 5, 0xBE) ' Issue command READ_SCRATCHPAD

temp = Ow_Read(PORTb, 5)
temp = (Ow_Read(PORTb, 5) << 8) + temp

'--- Format and display result on Lcd

Display_Temperature(temp)
Delay_ms(520)

k= 129 ' read second
cteni_casu()
vteriny = cas
delay_ms(1)

k = 131 'read minute
cteni_casu()
minuty = cas
delay_ms(1)

k = 133 'read hours
cteni_casu()
hodiny = cas
delay_ms(1)

k = 143 'read control register
cteni_casu()
dummy1 = cas

transform_cas() 'transform and
zobraz_cas() 'show time on display
wend

end.

Jefferson Salazar
patece

posted on 2012/10/30 05:14:54 AM CET

GSM / GPRS

mq5 gas sensor, pic16f877a and gsm modem

Good day masters,
could you please help me in my final project regarding lpg leakage gas sensor with sms?..I could hardly start in my own scratch about the codes that i should burn into the microcontroller.. Thank you and more power. Hope to hear you soon..I am intending to use microC since it is user friendly.


these will be used:
mq5 gas sensor, pic16f877a and gsm modem

Mohamad Reza
mail.mohamad

posted on 2012/10/30 01:13:10 AM CET

Graphics & LCD

pcf8833 lcd mikropascal for avr

hi
is mikropascal for avr support pcf8833 chip driver of NOKIA 6610 lcd?
is there anyone to help me to drive it?

marek stručovský
mlike

posted on 2012/10/27 06:25:23 PM CEST

Audio & Speech

communication 16f877A and nrf 905 example

Hello,
I need communicate between 16f877a and nrf 905 but I cann´t it. Can somebody help me, only example of read and write operation will do me. Thank you very much Marek

AJ Sagrado
acer_jay

posted on 2012/10/18 11:28:01 PM CEST

Other Codes

Urgent, I need help! I need to convert these codes into MikroC codes......

// Program to make a voting machine using LCD

#include
#define msec 50
#define lcd_data_str_pin P2
sbit rs = P3^0; //Register select (RS) pin
sbit rw = P3^1; //Read write(RW) pin
sbit en = P3^6; //Enable(EN) pin
sbit ini_pin = P1^0; // Start voting pin
sbit stop_pin = P1^5; // Stop voting pin

sbit candidate_1=P1^1; //Candidate1
sbit candidate_2=P1^2; //Candidate2
sbit candidate_3=P1^3; //Candidate3
sbit candidate_4=P1^4; //Candidate4
int max = 0;
int carry = 0;
int arr[4];

int vote_amt[3],j;
unsigned int vote_1,vote_2,vote_3,vote_4;

void delay(int delay_time) // Time delay function
{
int j,k;
for(j=0;j<=delay_time;j++)
for(k=0;k<=1000;k++);
}

void lcd_cmd(unsigned char cmd_addr) //Function to send command to LCD
{
lcd_data_str_pin = cmd_addr;
en = 1;
rs = 0;
rw = 0;
delay(1);
en = 0;
return;
}

void lcd_data_str(char str[50]) //Function to send string
{
int p;
for (p=0;str[p]!='\0';p++)
{
lcd_data_str_pin = str[p];
rw = 0;
rs = 1;
en = 1;
delay(1);
en = 0;
}
return;
}

void lcd_data_int(unsigned int vote) //Function to send 0-9 character values
{
char dig_ctrl_var;
int p;
for (j=2;j>=0;j--)
{
vote_amt[j]=vote%10;
vote=vote/10;
}

for (p=0;p<=2;p++)
{
dig_ctrl_var = vote_amt[p]+48;
lcd_data_str_pin = dig_ctrl_var;
rw = 0;
rs = 1;
en = 1;
delay(1);
en = 0;
}
return;
}

void vote_count() // Function to count votes
{
while (candidate_1==0 && candidate_2==0 && candidate_3==0 && candidate_4==0);
if (candidate_1==1)
{
while (candidate_1 == 1);
{
vote_1 = vote_1 + 1;
}
}

if (candidate_2==1)
{
while (candidate_2 == 1);
{
vote_2 = vote_2 + 1;
}
}

if (candidate_3==1)
{
while (candidate_3 == 1);
{
vote_3 = vote_3 + 1;
}
}

if (candidate_4==1)
{
while (candidate_4 == 1);
{
vote_4 = vote_4 + 1;
}
}
}

void lcd_ini()
{
lcd_cmd(0x38);
delay(msec);
lcd_cmd(0x0E);
delay(msec);
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x81);
delay(msec);
lcd_data_str("Welcome!!!");
delay(100);
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x80);
delay(msec);
lcd_data_str( "Press" );
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("button");
delay(msec);

delay(msec);
lcd_cmd(0xC0);
delay(msec);
lcd_data_str("to");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("vote");
delay(100);
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x80);
delay(msec);
lcd_data_str("P1");
delay(msec);
lcd_cmd(0x84);
delay(msec);
lcd_data_str("P2");
delay(msec);
lcd_cmd(0x88);
delay(msec);
lcd_data_str("P3");
delay(msec);
lcd_cmd(0x8C);
delay(msec);
lcd_data_str("P4");
delay(msec);

vote_count();
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x85);
delay(msec);
lcd_data_str("Thank");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("You!!");
delay(100);
}

void results() // Function to show results
{
int i;
carry = 0;
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x80);
delay(msec);
lcd_data_str("Results");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("Are");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("Out");
delay(msec);

lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x80);
delay(msec);
lcd_data_str("P1");
delay(msec);
lcd_cmd(0x84);
delay(msec);
lcd_data_str("P2");
delay(msec);
lcd_cmd(0x88);
delay(msec);
lcd_data_str("P3");
delay(msec);
lcd_cmd(0x8C);
delay(msec);
lcd_data_str("P4");
delay(msec);

lcd_cmd(0xC0);
delay(100);
lcd_data_int(vote_1);
delay(msec);

lcd_cmd(0xC4);
delay(msec);
lcd_data_int(vote_2);
delay(msec);

lcd_cmd(0xC8);
delay(msec);
lcd_data_int(vote_3);
delay(msec);

lcd_cmd(0xCC);
delay(msec);
lcd_data_int(vote_4);
delay(300);

arr[0] = vote_1;
arr[1] = vote_2;
arr[2] = vote_3;
arr[3] = vote_4;

for( i=0; i<4; i++)
{
if(arr[i]>=max)
max = arr[i];
}

if ( (vote_1 == max) && ( vote_2 != max) && (vote_3 != max)&& (vote_4 != max) )
{
carry = 1;
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x82);
delay(msec);
lcd_data_str("Hurray!!!");
delay(50);
lcd_cmd(0xC4);
delay(msec);
lcd_data_str("P1");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("wins");
delay(msec);
}

if ( (vote_2 == max) && ( vote_1 != max) && (vote_3 != max)&& (vote_4 != max) )
{
carry = 1;
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x82);
delay(msec);
lcd_data_str("Hurray!!!");
delay(50);
lcd_cmd(0xC4);
delay(msec);
lcd_data_str("P2");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("wins");
delay(msec);
}

if ( (vote_3 == max) && ( vote_2 != max) && (vote_1 != max)&& (vote_4 != max) )
{
carry = 1;
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x82);
delay(msec);
lcd_data_str("Hurray!!!");
delay(50);
lcd_cmd(0xC4);
delay(msec);
lcd_data_str("P3");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("wins");
delay(msec);
}

if ( (vote_4 == max) && ( vote_2 != max) && (vote_3 != max)&& (vote_1 != max) )
{
carry = 1;
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x82);
delay(msec);
lcd_data_str("Hurray!!!");
delay(50);
lcd_cmd(0xC4);
delay(msec);
lcd_data_str("P4");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("wins");
delay(msec);
}

if (carry==0)
{
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x82);
delay(msec);
lcd_data_str("clash");
delay(50);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("between!!!");
delay(50);
if(vote_2 == max)
{
lcd_cmd(0xC5);
lcd_data_str("P2");
delay(50);
}
if(vote_3 == max)
{
lcd_cmd(0xC9);
lcd_data_str("P3");
delay(50);
}
if(vote_4 == max)
{
lcd_cmd(0xCD);
lcd_data_str("P4");
delay(50);
}
}
}

void main()
{
ini_pin = stop_pin = 1;
vote_1 = vote_2 = vote_3 = vote_4 = 0;
candidate_1 = candidate_2 = candidate_3 = candidate_4 = 0;
lcd_cmd(0x38);
delay(msec);
lcd_cmd(0x0E);
delay(msec);
lcd_cmd(0x01);
delay(msec);
lcd_cmd(0x80);
delay(msec);
lcd_data_str( "Press" );
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("init");
delay(msec);

delay(msec);
lcd_cmd(0xC0);
delay(msec);
lcd_data_str("to");
delay(msec);
lcd_cmd(0x14);
delay(msec);
lcd_data_str("begin");
delay(100);
while(1)
{
while(ini_pin != 0)
{
if (stop_pin == 0)
break;
}
if (stop_pin == 0)
{
break;
}
lcd_ini();
}

while(1)
{
results();
}
}




I'm using AT89S52 micro controller... please help me, i'm new here...

first | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 last