Forum Discussion
Altera_Forum
Honored Contributor
20 years agoSet a bit
hi
in my statement i declare static alt_u8 count ;//8 digital input static alt_u8 mem;# define bit0 count&0x01 //first bit of byte count # define fp mem&0x01 //first bit of byte mem # define true 1# define false 0 if ((bit0 ) & (!fp) { //.....make something fp=1; } if(!bit0) { fp=0; } //witn this software i would like to have e positive edge on my first button input but in during compilation i cannot assign bit0=1 or bit0=true i don't want to use rising edge capture but use this simple sw like usually i use in plc program Where do i make mistake ? How can i assign a value to bit0? thanks for ansuwers walter2 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by pmicro@Mar 13 2006, 10:53 AM hiin my statement i declare
static alt_u8 count ;//8 digital input
static alt_u8 mem;# define bit0 count&0x01 //first bit of byte count # define fp mem&0x01 //first bit of byte mem # define true 1# define false 0
if ((bit0 ) & (!fp)
{
//.....make something
fp=1;
}
if(!bit0)
{
fp=0;
}
//witn this software i would like to have e positive edge on my first button input
but in during compilation i cannot assign bit0=1 or bit0=true
i don't want to use rising edge capture but use this simple sw like usually i use
in plc program
where do i make mistake ?
how can i assign a value to bit0?
thanks for ansuwers
walter
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=13386)
--- quote end ---
--- Quote End --- count = count | 0x01; This (or 0x2, 0x4, etc) will set whatever bit in the variable you want. If you're trying to set a bit on a line (like the enable to a FIFO or something) you need to use a PIO.
- Altera_Forum
Honored Contributor
i made like this
typedef struct sBit { alt_u8 B0 :1; alt_u8 B1 :1; alt_u8 B2 :1; alt_u8 B3 :1; alt_u8 B4 :1; alt_u8 B5 :1; alt_u8 B6 :1; alt_u8 B7 :1; alt_u8 B8 :1; alt_u8 B9 :1; alt_u8 B10 :1; alt_u8 B11 :1; alt_u8 B12 :1; alt_u8 B13 :1; alt_u8 B14 :1; alt_u8 B15 :1; }sBit; typedef union sDato // Una Union differisce dalla struct per il fatto che il dato e' condiviso { alt_u8 W; sBit B; }sDato; sDato count; sDato mem; ..... ..... while(1) { count.W=IORD_ALTERA_AVALON_PIO_DATA(PM_IN_BASE); if(count.B.B0) & (!mem.B.B0) { //execute code mem.B.B0=true; } if(!count.B.B0) { mem.B.B0=false; } } //now it's functionally ciao walter