Hi Tijs, Thank you for sharing this with us. Could you send the modified file as an attachment?
Thanks, Joep 2010/4/28 Tijs <[email protected]>: > Hi, > > im pretty new to JAL but i needed 7 databits a while ago from a > software serial lib. I first patched the code to do 7 databits > hardcoded but i now changed the code such that the amount of databits > is configurable. > > Maybe one of you guys want to have a look at it and maybe add it to > the svn repos if its all okay. > > Here's the diff: > > Index: serial_software.jal > =================================================================== > --- serial_software.jal (revision 1999) > +++ serial_software.jal (working copy) > @@ -32,6 +32,11 @@ > const serial_sw_stopbits = 2 > end if > > +if (defined(serial_sw_databits) == false) then > + -- default is 8 databits > + const serial_sw_databits = 8 > +end if > + > procedure serial_sw_init() is > -- ouput/tx pin active or not according to invert > if serial_sw_invert then > @@ -165,11 +170,16 @@ > while INTCON_GIE loop > INTCON_GIE = false > end loop > + > + -- pre-shift right if we write less than 8 bits. > + if serial_sw_databits < 8 then > + data = data >> (8 - serial_sw_databits) > + end if > > if serial_sw_invert then > serial_sw_tx_pin = low > _usec_delay(serial_sw_bit_time) > - for 8 loop > + for serial_sw_databits loop > -- wait a whole bittime, less some usec for other actions > serial_sw_tx_pin = data_bit > data = data >> 1 > @@ -178,13 +188,13 @@ > -- add stop bit(s) > serial_sw_tx_pin = high > _usec_delay(serial_sw_stopbits * serial_sw_bit_time) > - > + > else > -- invert the data > data = ! data > serial_sw_tx_pin = high > _usec_delay((1_000_000/serial_sw_baudrate)-2) > - for 8 loop > + for serial_sw_databits loop > -- wait a whole bittime, less some usec for other actions > serial_sw_tx_pin = data_bit > data = data >> 1 > @@ -198,6 +208,7 @@ > -- restore old interrupt status > INTCON_GIE = old_gie > > + > end procedure > > > @@ -232,8 +243,8 @@ > > -- test if still startbit, otherwise restart > if !serial_sw_rx_pin then > - -- now fetch 8 bits > - for 8 loop > + -- now fetch nr. of data bits > + for serial_sw_databits loop > -- wait a whole bittime, less 5 usec for other actions > _usec_delay(serial_sw_bit_time) > -- shift new bit in > @@ -261,8 +272,8 @@ > > -- test if still startbit, otherwise restart > if serial_sw_rx_pin then > - -- now fetch 8 bits > - for 8 loop > + -- now fetch nr. of data bits > + for serial_sw_databits loop > -- wait a whole bittime, less 5 usec for other actions > _usec_delay(serial_sw_bit_time) > -- shift new bit in > @@ -277,6 +288,11 @@ > end if > end loop > end if > + > + if serial_sw_databits < 8 then > + -- shift right since we read less than 8 bits. > + data = data >> (8 - serial_sw_databits) > + end if > > -- restore old interrupt status > INTCON_GIE = ie_old > @@ -333,8 +349,8 @@ > -- wait half a bit time, less 5 usec for other actions > _usec_delay(serial_sw_bit_time / 2) > > - -- now fetch 8 bits > - for 8 loop > + -- now fetch nr. of data bits > + for serial_sw_databits loop > -- wait a whole bittime, less 5 usec for other actions > _usec_delay(serial_sw_bit_time) > -- shift new bit in > @@ -350,8 +366,8 @@ > -- wait half a bit time, less 5 usec for other actions > _usec_delay(serial_sw_bit_time / 2) > > - -- now fetch 8 bits > - for 8 loop > + -- now fetch nr. of data bits > + for serial_sw_databits loop > -- wait a whole bittime, less 5 usec for other actions > _usec_delay(serial_sw_bit_time) > -- shift new bit in > @@ -362,6 +378,11 @@ > end loop > end if > > + -- shift right if we read less than 8 bits. > + if serial_sw_databits < 8 then > + data = data >> (8 - serial_sw_databits) > + end if > + > -- restore old interrupt status > INTCON_GIE = ie_old > > -- > You received this message because you are subscribed to the Google Groups > "jallib" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/jallib?hl=en. > > -- You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jallib?hl=en.
